Check if string contains another string unordered

Get help using Construct 2

Post » Thu Jul 25, 2013 10:37 am

Hello there,

I would explain it with the examle:

The game needs a pattern matching algorithm. E.g. there's a list of all possible patterns as 2d array coordintates (as string):

Here's one possible pattern:
0,1 0,2 0,3 1,1 1,2 1,3

Than I have a set of 2d array coordinates, that I would like to check if it contains a pattern from the list (the string above):
5,4 0,0 0,1 0,2 0,3 0,4 1,1 1,2 1,3

How to check if the 2nd string contains all the pairs from the first string, despite of order of pairs?

xoros2013-07-25 10:47:24
B
45
S
11
G
4
Posts: 511
Reputation: 7,381

Post » Thu Jul 25, 2013 10:48 am

You could use the system expression

find(src, text)
Find the first index within src that text occurs, else returns -1.

So if the result of that expression is something else than -1 the pattern exists within the text.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jul 25, 2013 11:01 am

Ah, this will only work if both strings are exactly the same or pairs have the same order. I think may be Regex could help, but the biggest problem here is the order of pairs, the search should be unordered.
B
45
S
11
G
4
Posts: 511
Reputation: 7,381

Post » Thu Jul 25, 2013 12:04 pm

If you only want to check if the pair exists within the string they dont have to be the same? if not -1 it exists.

But probably I don't understand what you are trying to accomplish.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jul 25, 2013 1:01 pm

Ok, I thought it would be possible to check the whole string at once, but I had to do it for each pair - it works like this.
B
45
S
11
G
4
Posts: 511
Reputation: 7,381


Return to How do I....?

Who is online

Users browsing this forum: alextro, christina, Kyatric, omnipaws, ThePlagueDoctor and 7 guests