LET tok = base.StringTokenizer.create(mystr,",")WHILE tok.hasMoreTokens() DISPLAY tok.nextToken()END WHILE
LET i = 0LET tok = base.StringTokenizer.create(mystr,",")WHILE tok.hasMoreTokens() LET i = i + 1 CASE i WHEN 3 LET l_third = tok.nextToken() WHEN 4 LET l_fourth = tok.nextToken() WHEN 7 LET l_seventh = tok.nextToken() OTHERWISE LET l_dummy = tok.nextToken() END CASEEND WHILE
DEFINE l_arr DYNAMIC ARRAY OF STRINGCALL l_arr.clear()LET tok = base.StringTokenizer.create(mystr,",")WHILE tok.hasMoreTokens() CALL l_arr.appendElement() LET l_arr[l_arr.getLength()] = tok.nextToken()END WHILELET l_third = l_arr[3]LET l_fourth = l_arr[4]LET l_seventh = l_arr[7]
LET tok = base.StringTokenizer.create(mystr,",")LET l_third = tok.token(3)LET l_fourth = tok.token(4)LET l_seventh = tok.token(7)
IMPORT java java.lang.StringMAIN DEFINE result ARRAY[] OF java.lang.String DEFINE s java.lang.String DEFINE r String DEFINE x, n INT LET s = "this is a test" LET result = s.split("\\s") LET n = result.getLength() FOR x = 1 TO n LET r = result[x] DISPLAY x, " ", r END FOREND MAIN
$fglcomp xx.4gl && fglrun xx.4gl 1 this 2 is 3 a 4 test
TYPE stringArray DYNAMIC ARRAY OF STRING MAINDEFINE r stringArrayDEFINE i INTEGER CALL string_split("This is a test"," ",r) FOR i = 1 TO r.getLength() DISPLAY i, " ",r[i] END FOREND MAIN FUNCTION string_split(string,delimiter,result)DEFINE string, delimiter STRINGDEFINE result stringArrayDEFINE tok base.StringTokenizer CALL result.clear() LET tok = base.StringTokenizer.createExt(string,delimiter, "\\", TRUE) WHILE tok.hasMoreTokens() LET result[result.getLength()+1] = tok.nextToken() END WHILEEND FUNCTION