Today, I responded on a Partner Forum thread about evaluating the contents of a string field. The question was:
“Is there a function that evaluates a string field to determine if it contains any special characters?”
I have written similar code in the past and decided to quickly create a function to perform two functions:
- Return a Boolean to indicate if a special character has been found
- Pass out a string containing only the normal (non-special) characters
This function identifies alphabetic (optionally including space) and numeric characters as normal and anything else as “special”.
Global Function: IsSpecial
function returns boolean OUT_Special; in string IN_String; in boolean IN_SpaceAllowed; out string OUT_Stripped; local string l_char; local string l_string; local integer i; OUT_Special = false; clear l_string; for i = 1 to length(IN_String) do l_char = substring(IN_String, i, 1); if isalpha(l_char, IN_SpaceAllowed) or (l_char >= str(0) and l_char <= str(9)) then l_string = l_string + l_char; else OUT_Special = true; end if; end for; OUT_Stripped = l_string;
The function uses the Dexterity isalpha() function as this will handle the extra extended alphabetic characters beyond the normal A to Z and a to z ranges such as é è ë ö ÿ etc.
I have also provided the option to decide whether spaces are to be included as alphabetic.
Hope you find this helpful.
This article was originally posted on http://www.winthropdc.com/blog.