Created On:  12 October 2011
 
It does not seem possible to use escape characters in SilkTest.  MatchStr cannot escape wildcards.  The below example demonstrates this:

[-] testcase EscapeChar () appstate none
 [ ] STRING sEncyp = "123***789"
 [ ] STRING sNonEncyp = "123456789"
 [-] if (MatchStr(sEncyp,"*'*'*"))
  [ ] Print ("Number contans asterisks "+ sEncyp)
 [-] else
  [ ] Print ("Number does not contans asterisks "+ sEncyp)
  [ ]
 [-] if (MatchStr(sNonEncyp,"*'*'*"))
  [ ] Print ("Number contans asterisks "+ sNonEncyp)
 [-] else
  [ ] Print ("Number does not contans asterisks "+ sNonEncyp)


The above testcase will incorrectly return the following results:

[-] Testcase EscapeChar - Passed
 [ ] Number does not contans asterisks 123***789
 [ ] Number does not contans asterisks 123456789

Is it possible to use an escape character with function MatchStr to check if an integer/string contains wildcards?


You can achieve this by using function StrPos() to return the position of the wildcard.  See the example below:

[-] testcase EscapeChar2 () appstate none
 [ ] STRING sEncyp = "123***789"
 [ ] STRING sNonEncyp = "123456789"
 [-] if (containsAsterisk(sEncyp))
  [ ] Print ("Number contains asterisks "+ sEncyp)
 [-] else
  [ ] Print ("Number does not contain asterisks "+ sEncyp)
 [-]  if (containsAsterisk(sNonEncyp))
  [ ] Print ("Number contains asterisks "+ sNonEncyp)
 [-] else
  [ ] Print ("Number does not contain asterisks "+ sNonEncyp)
  [ ]
[-] BOOLEAN containsAsterisk(String toCheck)
 [ ] INTEGER val
 [ ] val = StrPos("*", toCheck)
 [-] if(val>0)
  [ ] return true
 [-] else
  [ ] return false



The above testcase will correctly return the following results:

[-] Testcase EscapeChar2 - Passed
 [ ] Number contains asterisks 123***789
 [ ] Number does not contain asterisks 123456789