主题:截取一个字符串的问题
tabno
[专家分:0] 发布于 2007-06-22 10:10:00
用户从控件输入一个长字符串,以“,”或者空格隔开,如:E0023Y01,E0023Y02,K0234 K0235
我如何才能用,或者空格把这个字符串分割开,分割得到的结果我要用来和数据库中进行比较。
主要因为我不熟,不清楚除了用到left,right,mid,len这几个函数外,还有一些什么函数???
恳请赐教
最后更新于:2007-06-22 10:25:00
回复列表 (共4个回复)
沙发
tabno [专家分:0] 发布于 2007-06-22 10:32:00
哈哈,我找到这个函数拉,是Pos函数
但是谁能告诉我用Pos函数去查找逗号或空格位置时,逗号或空格如何表示呢?[em1]
板凳
tabno [专家分:0] 发布于 2007-06-22 10:46:00
TF1 help里面有如下这个例子
hese statements separate the return value of GetBandAtPointer into the band name and row number. The Pos function finds the position of the tab in the string and the Left and Mid functions extract the information to the left and right of the tab:
string s, ls_left, ls_right
integer li_tab
s = dw_groups.GetBandAtPointer()
[color=FF0000]li_tab = Pos(s, "~t", 1)[/color]
ls_left = Left(s, li_tab - 1)
ls_right = Mid(s, li_tab + 1)
You could write similar code for a generic parsing function with three arguments. The string s would be an argument passed by value and ls_left and ls_right would be strings passed by reference.
[color=FF0000]通过例子我明白了查找特殊符号制表符(~t)等的方法,但是逗号和空格是不是不属于特殊符号,直接用Pos(s, ",", 1),Pos(s, " ", 1)就可以了?谁能给 指点一下??,另外中英文的逗号都是一回事吗?[/color]
3 楼
tabno [专家分:0] 发布于 2007-06-22 11:02:00
自己在程序里面测试了一下
S089300Y01,s02 s03,s04 s05//英文逗号,英文空格,中文逗号,中文空格
integer a,b,c,d
a=Pos(ls_ekey,",",1)//11
b=Pos(ls_ekey," ",1)//15
c=Pos(ls_ekey,",",1)//19
d=Pos(ls_ekey," ",1)//15
[color=FF0000]所以中英文的逗号是不一样的,但是空格是一样的!
我说的对不?[/color]
我继续自己观察了一下,发现好象中英文的空格都是占一个字符,而逗号则不同,中文是两个字符,而英文是一个字符,这个才是区别的根本原因,正确否??怎么也没高人指点一二???[em10]
4 楼
sam2080 [专家分:20] 发布于 2007-07-04 16:08:00
恩,就如你所说
可以用POS来判断,在从该位置往后判断,一个个的截取
我来回复