Mitch_Denis_38

Finding a special character within a string with STR_FIND (AE)

Discussion created by Mitch_Denis_38 on Dec 11, 2014
Latest reply on Dec 11, 2014 by Mark_Hadler_430
There's been some discussion recently regarding finding special characters within a string to ensure that they aren't in the string.  This is particularly with a :READ.  Something like:

:beginread "Request new file info" :  read &vara#, ,,"Put in name of file" :endread

But you don't want there to be a * or " in there because that's an illegal character.  There is the option in V9 and V10 to use Regular Expressions in Promptsets, but that may not be an option, or you may be using 8.00A which does not have Promptsets.

At that point, one solution to this is to use STR_FIND to look for the special character and exit the script or job you're using with a specific return code.  Here is an example of what that code might look like:

!read in values :beginread "Request new file info" :  read &vara#, ,,"Put in name of file" :endread !create flag set to false by default looking for a reserved character :set &reserved_flag# = 'false' !if * was found - it will return as not 0 below, set reserved_flag to true :if str_find(&vara#, '*') <> 0 :  set &reserved_flag# = 'true' :endif !if " was found - it will return as not 0 below, set reserved_flag to true :if str_find(&vara#, '"') <> 0 :  set &reserved_flag# = 'true' :endif !if reserved_flag is true, exit with exit code 10 :if &reserved_flag# = 'true' :  exit 10 :endif
There are definitely other ways to do this as well.  If anyone has any, please feel free to share!

Outcomes