3

Suppose I have a text variable $$string. How can I write a boolean to check whether $$string contains the text $$substring?

e.g. if $$string is "foobar" and $$substring is "oo", then the result should be True, and if the $$string is "foo" and $$substring is "bar" the result should be False.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535

2 Answers2

3

For a problem like this I'm partial to the PatternCount function:

 PatternCount($$string ; $$substring)

You should then get back false = 0 or true >= 1. You can force true to 1 as follows:

 PatternCount($$string ; $$substring) > 0

Function Definition here: http://fmhelp.filemaker.com/fmphelp_10/en/html/func_ref3.33.73.html

pft221
  • 1,729
  • 1
  • 12
  • 19
1

Use the Position function:

Position($$string;$$substring;1;1)>0

Note: Position($$string;$$substring;a;b) checks whether $$substring is contained at least b-times in $$string from starting position a, and returns where the b th occurrence is located in $$string, or -1 if there is no b th occurrence. Counting starts from 1.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
  • FileMaker text positions are 1-indexed, and 0 is used to indicate that the selection is out of range. So you need to modify your function slightly: Position( $$string; $$substring; 1; 1) > 0 – Jesse Barnum Mar 02 '12 at 17:06