如何分割字符串?(50分)

S

sj888

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将一个含有字母和汉字的字符串分割成两部分(不能把汉字分开)?
 
汉字的两ASCII码都大于0xA0,接下来就好办了
 
if chr(string[iPos])>$A0 and chr(string[iPos+1])>$A0 then

the string[iPos] and string[iPos+1] is one chinese char
else
it is not
so
for i:= 0 to .....do
if isAChineseChar(string) then
copy 0to i-1
else
continue ;
it is ok?
 
告诉你一个非常有用的函数。
bytetype 它可以判断一个字符串中,某个 Char 是单个字母,还是双字节的前一位或
后一位。
mbSingleByte 单字母
mbLeadByte 双字节第一位
mbTrailByte 双字节第二位
 
var s:widestring;
s1:string;
begin
s1:='切割字符串';
s:=s1;
s:=copy(s1,2,2);//s='割字'
end;
好啦,就是这样,分割还不容易吗?只要先把字符串赋值给widestring的变量就行了
 
widestring
 
谢谢! 郭镇松的答案比较好!
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
165
swish
S
S
回复
0
查看
454
swish
S
回复
0
查看
862
不得闲
回复
0
查看
670
不得闲
顶部 底部