This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
Is there a benefit to using FindString != -1 vs. Contains as an if, then qualifier? I know the benefit of using contains is that it gives the case insensitive option which you can't do with findstring without uppercase([field]) or lowercase([field]), but is there a downside to using this over findstring?
If the context of the string is important, the findstring function let's you know where it was found. It can be very helpful if you are going to perform other string functions.
The regex_match function will give you super powers. Using it, you can be case sensitive or insensitive and add patterns as well counts of matches (regex_countmatches) to see if it contains many targets.
I hope that this helps you.
Alteryx ACE & Top Community Contributor
Chaos reigns within. Repent, reflect and reboot. Order shall return.
FindString will actually tell you the position of the field you're looking for, whereas Contains just tells you whether or not it finds the string as a True/False answer.
So if you only need to know whether or not a string contains something else (i.e. "Green Apples" contains the word "Apple" but "Bartlett Pears" does not), then I would use Contains, especially because it has the option of making it case sensitive...
But if you need to know at which character "Apple" starts so that you can parse out anything in front of it, then you might want to use FindString.
Contains("Green Apples","Apples") = -1 (<-- Which in this case means True) FindString("Green Apples","Apples") = 6
Although it's not in line with the original question, this is a great example to leverage RegEx. If only full version numbers are required then using the below in a RegEx tool with the Output method set to Parse will pull out the examples.
If the full path contains a non-version number (eg. TOMCAT, BOTOMCAT) and this is required - then by first trimming the field of '\' and '/' and then using the below RegEx replace to isolate the final component of the full path, these can also be obtained.
if isnull([Full Version]) then REGEX_Replace([Field1], '.*\/|.*\\', '')
else [Full Version]