https://tzunghua.blogspot.tw/2012/02/4gl-split.html
##################################################################################################
# 字串切割成Array
# @author : JeffreyWu
# @date : 2012-02-10
# @param : p_str [STRING] 來源字串 Ex:/u1/out/1234.txt
# @param : p_delimiter [STRING] 分裂字符 Ex:","
# @param : p_RemoveEmpty [BOOLEAN] 是否移除空白Array Ex:TRUE Or FALSE
# @return : p_arr [DYNAMIC ARRAY OF STRING]
# @description : 字串切割成Array
##################################################################################################
FUNCTION sl_Split(p_str,p_delimiter,p_RemoveEmpty)
DEFINE p_str STRING
DEFINE p_delimiter STRING
DEFINE p_tok base.StringTokenizer
DEFINE p_arr DYNAMIC ARRAY OF STRING
DEFINE p_RemoveEmpty BOOLEAN
DEFINE p_tokStr STRING
LET p_tok = base.StringTokenizer.createExt(p_str,p_delimiter,"",TRUE)
CALL p_arr.clear()
WHILE p_tok.hasMoreTokens()
LET p_tokStr = NULL
LET p_tokStr = p_tok.nextToken()
IF p_RemoveEmpty THEN
IF p_tokStr.getLength() > 0 THEN
CALL p_arr.appendElement()
LET p_arr[p_arr.getLength()] = p_tokStr
END IF
ELSE
CALL p_arr.appendElement()
LET p_arr[p_arr.getLength()] = p_tokStr
END IF
END WHILE
RETURN p_arr
END FUNCTION
沒有留言:
張貼留言