1. Tracy Lamb
  2. PowerBuilder
  3. Wednesday, 21 June 2023 15:07 PM UTC

Hi all,

I need to look for special characters in a string before further processing.  The character(s) could be anywhere in the string.  I think the Match() function works fine, but don't know how to form the match pattern.  The characters I'm looking for are:

  • < or > (Less than or greater than)
  • : (Colon)
  • “ (double quote)
  • / (forward slash)
  • \ (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • * (asterisk)

This code works, but I'm wondering how to add a double quote ( " )  to the match...

// Make sure there aren't any disallowed characters in ls_CalProcedure
lb_match = Match(ls_CalProcedure, "[<>:/\|]")
if lb_match = true then
	MessageBox("Add Attachment", "The Cal Procedure cannot contain any of the following special characters:~r~n < > :  /  \  |  ? * ", StopSign!)
	return -1
end if

 

~~~Tracy

Accepted Answer
Mark Goldsmith Accepted Answer Pending Moderation
  1. Wednesday, 21 June 2023 15:57 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Tracy...just change your text pattern to be enclosed in single quotes, something like '[<>:/"\|]'

HTH...regards,

Mark

Comment
  1. Tracy Lamb
  2. Wednesday, 21 June 2023 17:22 PM UTC
Thank you Mark! Works like a charm!
  1. Helpful
  1. Mark Goldsmith
  2. Wednesday, 21 June 2023 17:32 PM UTC
You're very welcome Tracy. Thanks for the update and glad to hear that worked for you!
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 21 June 2023 16:17 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Tracy -

In addition to Mark's excellent suggestion, I use a couple of techniques in situations where "special" characters need to be included in the match template. One is to use the backslash (\) metacharacter, as it removes the following character's special characteristics (if it happens to be a metacharacter) so that it matches itself.

For example:

lb_match = Match(ls_CalProcedure,'[\:\"\/\\\|\?\*]')

Another "trick" is to construct the match template using concatenated strings, for example:

// Matches a-z, grave, pipe, open/close curly brace, and tilde.
lb_result = Match(ls_value,"[a-z\`\|\{\}\" + "~~" + "]')

Best regards, John

Comment
  1. Tracy Lamb
  2. Wednesday, 21 June 2023 17:25 PM UTC
Nice!
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.