该字符串处理目的是去除该字符串前后中间多余的顿号!
可是在使用length函数遇到问题,它误把一个汉字当成两个字符,使我的程序不能正确处理多余的顿吗?请问如何解决!程序:
---------------------------------------------------------------------
main.istinfo12.Text:='、、纺织品、、、、成衣及配件、、'; main.istinfo12.Text:=AnsiReplaceStr(main.istinfo12.Text,'、、、','、');
main.istinfo12.Text:=AnsiReplaceStr(main.istinfo12.Text,'、、','、');
if leftstr(main.istinfo12.Text,1)='、' then
begin
main.istinfo12.Text:=midstr(main.istinfo12.Text,2,length(main.istinfo12.Text)-1);
end;
if rightstr(main.istinfo12.Text,1)='、' then
begin
main.istinfo12.Text:=midstr(main.istinfo12.Text,1,length(main.istinfo12.Text)-1);
end;
istinfotxt.Caption:=datamodule1.ADOQuery2.FieldByName('Name_Cn').AsString;---------------------------------------------------------------------
可是在使用length函数遇到问题,它误把一个汉字当成两个字符,使我的程序不能正确处理多余的顿吗?请问如何解决!程序:
---------------------------------------------------------------------
main.istinfo12.Text:='、、纺织品、、、、成衣及配件、、'; main.istinfo12.Text:=AnsiReplaceStr(main.istinfo12.Text,'、、、','、');
main.istinfo12.Text:=AnsiReplaceStr(main.istinfo12.Text,'、、','、');
if leftstr(main.istinfo12.Text,1)='、' then
begin
main.istinfo12.Text:=midstr(main.istinfo12.Text,2,length(main.istinfo12.Text)-1);
end;
if rightstr(main.istinfo12.Text,1)='、' then
begin
main.istinfo12.Text:=midstr(main.istinfo12.Text,1,length(main.istinfo12.Text)-1);
end;
istinfotxt.Caption:=datamodule1.ADOQuery2.FieldByName('Name_Cn').AsString;---------------------------------------------------------------------
如何把main.istinfo12.Text设为Unicode字符类型
StringReplace代替AnsiReplaceStr函数
把
main.istinfo12.Text:=midstr(main.istinfo12.Text,1,length(main.istinfo12.Text)-1);
改为
main.istinfo12.Text:=midstr(main.istinfo12.Text,1,length(widestring(main.istinfo12.Text))-1);
vars:WideString;begin
s:=main.istinfo12.Text;
s:=StringReplace(s,'、、、','、',[rfReplaceAll]);s:=StringReplace(s,'、、','、',[rfReplaceAll]);
....应该可以解决的,算是给你点资料吧
如何把main.istinfo12.Text设为Unicode字符类型怎么变????
//const S, OldPattern, NewPattern
begin
str1:=StringReplace(str1,str2,str3,[rfReplaceAll]);
str1:=StringReplace(str1,str2,str3,[rfReplaceAll]);
if leftstr(str1,1)=str3 then
begin
str1:=midstr(str1,2,length(str1)-1);
end;
if rightstr(str1,1)=str3 then
begin
str1:=midstr(str1,1,length(widestring(str1))-1);
end;
Result:=str1;
end;
如何把main.istinfo12.Text设为Unicode字符类型改成这样:length(widestring(main.istinfo12.Text))