Boolean for whether a string contains a substring

此生再无相见时 提交于 2019-12-12 12:34:30

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/9537267/boolean-for-whether-a-string-contains-a-substring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!