[basic] compare string

Get help using Construct 2

Post » Fri Jan 03, 2014 2:35 pm

how to compare 2 string that showed the result is almost true ...

string 1 = Bill Gates
string 2 = Bill

result = almost true

is there a good way to do this ????
B
12
S
2
G
2
Posts: 54
Reputation: 2,144

Post » Fri Jan 03, 2014 2:54 pm

You'd need to specify a bit more for what you consider 'almost true'. There are a bunch of string expressions, but from this example it's not clear what you want. Do you mean X letters are the same, X words, the words at the beginning, any words are the same...?
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Fri Jan 03, 2014 3:13 pm

Or do you mean something like soundex? Im not so shure this can be done in c2.

I'd go with blackhornet's way and go compare the first word.
B
22
S
7
G
4
Posts: 154
Reputation: 3,699

Post » Fri Jan 03, 2014 3:21 pm

take a look in the manual for find()


something like   find(varwithtext, "stringtolookfor")

if stringtolookfor does not occur in varwithtext, it should get you a -1

For every occurence, it will add 1 to the result.


I think this is the implementation of javascripts IndexOf


variable = "long text with some stuff"

find(variable, "stuff")

should give you 0

variable = "long stuffed text with some stuff"

find(variable, "stuff")

should give you 1
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562


Return to How do I....?

Who is online

Users browsing this forum: el3um4s, imothep85, Ryan Kocourek, TheSupreme, TylerJS and 13 guests