该字符串处理目的是去除该字符串前后中间多余的顿号!
可是在使用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;---------------------------------------------------------------------

解决方案 »

  1.   

    将字符串都强制转换成widestring类型
      

  2.   

    Returns a string with occurrences of one substring replaced by another substring.UnitSysUtilsCategorystring handling routinesDelphi syntax:function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;C++ syntax:extern PACKAGE AnsiString __fastcall StringReplace(const AnsiString S, const AnsiString OldPattern, const AnsiString NewPattern, TReplaceFlags Flags);DescriptionStringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern. StringReplace assumes that the source string may contain Multibyte characters.S is the source string, whose substrings are changed.OldPattern is the substring to locate and replace with NewPattern.NewPattern is the substring to substitute for occurrences of OldPattern.Flags is a set of flags that govern how StringReplace locates and replaces occurrences of OldPattern. If Flags does not include rfReplaceAll, StringReplace only replaces the first occurrence of OldPattern in S. Otherwise, StringReplace replaces all instances of OldPattern with NewPattern. If the Flags parameter includes rfIgnoreCase, The comparison operation is case insensitive.s:=StringReplace(main.istinfo12.Text,'、','',[rfReplaceAll])
      

  3.   

    length(main.istinfo12.Text)
    如何把main.istinfo12.Text设为Unicode字符类型
      

  4.   

    TO:madyak(无天)首先谢谢你的回答,该函数好是好,可是不太适合我!我是指去掉多余的顿号,而不是全部;)
      

  5.   

    还是按你的方法用WideString宽字符,可以解决汉字占两个字符的问题;
    StringReplace代替AnsiReplaceStr函数
      

  6.   

    解决了!

              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);
      

  7.   

    s:=StringReplace(main.istinfo12.Text,'、、','、',[rfReplaceAll])
      

  8.   

    把你的方法略加修改
    vars:WideString;begin
    s:=main.istinfo12.Text;
    s:=StringReplace(s,'、、、','、',[rfReplaceAll]);s:=StringReplace(s,'、、','、',[rfReplaceAll]);
    ....应该可以解决的,算是给你点资料吧
      

  9.   

    回复人: 0754boy(李昂) ( ) 信誉:100  2003-09-10 17:13:00  得分:0 length(main.istinfo12.Text)
    如何把main.istinfo12.Text设为Unicode字符类型怎么变????
      

  10.   

    编成一个自定义函数! ^-^function idelredundancechar(str1,str2,str3:string):string ;
    //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;
      

  11.   

    TO:xiaoyuehen(萧月痕)length(main.istinfo12.Text)
    如何把main.istinfo12.Text设为Unicode字符类型改成这样:length(widestring(main.istinfo12.Text))