我发现一个问题length() ansipos() 把一个汉字看成两个长度leftstr() rightstr() midstr() 把一个汉字看成一个长度,我的程序里要同时用这些函数转换,可怜我不字符串里还有汉字总是达不到我想要的结果请问有什么办法,实现length() ansipos() 把一个汉字看成一个长度正常情况下length('abc中国')=7
我想length('abc中国')=5 实在没办法了,就写自定义函数,给个思想也行,分不多了,谢谢解

解决方案 »

  1.   

    可以用widestring实现,widestring是unicode字符串。
    var
      s : widestring;
    begin
      s := 'abc中国';
      showmessage (s + ' ' + inttostr (length (s)));
    end;
      

  2.   

    用widestringFor single-byte and multibyte strings, Length returns the number of bytes used by the string. For Unicode (WideString) strings, Length returns the number of bytes divided by two.