like feature in if condition

Author: lalitpct@gmail.com (lalitpct)

How do we put 'like' in if condition , like as shown below if ($$VAR_1 like '%%NAT% | $$VAR_1 like '%%MAT%')

3 Comments

  1. Hi lalit, you can check with $scan if a string contains a substring: if ($scan($$VAR_1,'nat') > 0 | $scan($$VAR_1,'mat') > 0) ... endif have a look at $scan in the documenation (here 9601x101) $scan Find a substring within a string. $scan (Source, SearchFor) Parameters Source—string in which the substring needs to be found. SearchFor—substring to search for. SearchFor can be a constant string or a syntax string. Return Values Position of the substring within the string.


    Author: ulrich-merkel (ulrichmerkel@web.de)
  2. Hi lalit, Using the $syntax function allows you to test for wildcard matches. Something like $$var_1 = $syntax("NAT*") | $$var_1 = $syntax("MAT*") Possibly even searchvar = "NAT*|MAT*" if($$var_1 = $syntax(searchvar)) I have to remind myself every time whether the * and | signs have to be gold* and gold| before applying $syntax, but it's fairly easy to test. Iain


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)
  3. just an addition to Iains post: if you use lowercase in syntax strings, they match upper and lowercase, while if you use uppercase characters, they do not match lowercase ones. See "Syntax Strings for Pattern Matching" in the helpfile for more info. In my example above, the single quotes denote a syntax string and because they are lovercase they will retrun true for "nature", "mature", "MaT", "MAT","just a natural" etc.


    Author: ulrich-merkel (ulrichmerkel@web.de)