123大哥/456小二/789礼物/...
如上,怎么分别取得
st1:123大哥
st2:456小二
st3:789礼物
结果值是:3列
判断字符"/"
------解决方案--------------------
int count = 0 // 列数
string ls_source = "123大哥/456小二/789礼物/...", ls_buf
string lsa_result[]
do
ls_buf = f_get_token(ls_target)
if ls_buf = "" then exit
count ++
lsa_result[count] = ls_buf
loop while true
// f_get_token()
/*
功能:(重载)
按指定的分隔符分解另一个字符串(返回分隔符前的字符串,并把它从源字符串中删除)
参数:
source: 源字串(输出)
separator: 分隔符
返回值:
返回字符串
String Function GET_TOKEN (ref string Source, readonly string Separator)
The function Get_Token receive, as arguments, the string from which
the token is to be stripped off, from the left, and the separator
character. If the separator character does not appear in the string,
it returns the entire string. Otherwise, it returns the token, not
including the separator character. In either case, the source string
is truncated on the left, by the length of the token and separator
character, if any.
*/
int p
string ret
p = Pos(source, separator) // Get the position of the separator
if p = 0 then // if no separator,
ret = source // return the whole source string and
source = "" // make the original source of zero length
else
ret = Mid(source, 1, p - 1) // otherwise, return just the token and
source = Right(source, Len(source) - p) // strip it & the separator
end if
return ret
------解决方案--------------------
不好意思,漏了分隔符;而且不够严谨!
// 严谨的写法
do
ls_buf = f_get_token(ls_source, "/")
count ++
lsa_result[count] = ls_buf
messagebox("第 " + string(count) + " 列", lsa_result[count])
loop while ls_source <> ""