Finding text in a string


#1

How do I compare 2 strings to see if one string contains part of the other.

For example:

Sting1= ‘next holiday is Labor Day’
'String2 = ‘Labor Day’

If string1 contains string2 result returns true
Else
Result returns false


#2

Use expressions, use the contains() function as described on the wiki here.


#3

So is the correct syntax

  1. boolean(contains(string1),(string2))
    Or
  2. (boolean(contains(string1),(string2)))

#4

According to docs:

contains(haystackString, needleString)

#5

I’m doing something wrong, I just am not sure what’s?


#6

If you define the value of a variable you tell webCoRE to always initialize it. That result variable should be a boolean one, not string, and it should be given no value at all - leave it not defined


#7

I tried it out of curiosity… same result as what op got.

define
string str1 = ‘Tom’;
string str2 = ‘Tomas’;
end define;

(expression) contains(str1,str2) »»» (boolean) false

Edit: my params backassward… lol
(expression) contains(str2,str1) »»» (boolean) true


#8

Variables that have values are never actually saved anywhere because they are constants. You’re changing your testing procedure completely - too many changes :wink: leave the result variable in place, or use log to console in the piston and test it - the evaluation console may not have access to constants because of the reason explained. That should probably be fixed