/********************************* REXX ***********************************/ /* Bruce A. Woodworth STRIPOP September 22, 2002 */ /* */ /* This REXX EXEC removes a string from a string. */ /* */ /* This EXEC accepts 2 strings. The first is the string which will be */ /* returned. The second is the string which will be stripped from the */ /* first string. */ /* */ /* Syntax: */ /* STRIPOP( option_string, keyword ) */ /* */ /* Ex: */ /* STRIPOP( THE_OPTIONS, "/CNT" ) */ /* */ /* In this example, the string, THE_OPTIONS, will be scanned for the */ /* word /CNT. If it is found, then the string, /CNT, will be stripped */ /* from THE_OPTIONS and THE_OPTIONS will then be returned. */ /* */ /**************************************************************************/ parse upper arg the_options, the_keyword if the_options = "?" ³ the_keyword = "" ³ the_options = "" then do option_val = 0 init = setinit() logon_id = userid() 'disphelp' setrexx(init) ³³ '(stripop)' end else call check_option return(option_val) check_option: if the_options = the_keyword then option_val = "" else call reformat_option_string return reformat_option_string: keyword_loc = index(the_options, the_keyword) keyword_size = truelen(the_keyword) option_size = length(the_options) if keyword_loc = 0 then option_val = the_options else do if keyword_loc = 1 then call grab_second_half else call grab_around_string end return grab_second_half: string_start = keyword_size + 1 check_next_byte = substr(the_options,string_start,1) do while check_next_byte = " " string_start = string_start + 1 check_next_byte = substr(the_options,string_start,1) end throw_away = string_start - 1 string_size = option_size - throw_away option_val = substr(the_options,string_start,string_size) return grab_around_string: first_size = keyword_loc - 1 first_piece = substr(the_options,1,first_size) second_size = option_size - keyword_size - first_size second_loc = keyword_loc + keyword_size second_piece = substr(the_options,second_loc,second_size) if second_size > 0 then temp_string = first_piece ³³ second_piece else temp_string = first_piece call remove_trailing_blanks return remove_trailing_blanks: option_val = "" new_size = length(temp_string) last_char = substr(temp_string,new_size,1) do while last_char = " " & new_size > 1 new_size = new_size - 1 last_char = substr(temp_string,new_size,1) end if new_size = 1 & last_char = " " then option_val = "" else option_val = substr(temp_string,1,new_size) return