procedure TForm1.Button2Click(Sender: TObject);
var
  ss: string;
begin
  ss := '测s试ss';
  showmessage(copy(ss,1,1));//测
  showmessage(copy(ss,1,2));//测s
  showmessage(copy(ss,1,3));//测s试
  showmessage(copy(ss,1,4));//测s试s
  showmessage(copy(ss,1,5));//测s试ss
  showmessage(copy(ss,1,6));//测s试ss  showmessage(copy(ss,0,1));//测
  showmessage(copy(ss,1,1));//测
  showmessage(copy(ss,0,2));//测end;string改了类型后,好像使用起来不习惯哦。谁帮忙总结下。

解决方案 »

  1.   

    unicode字符集,就是这个样子。
      

  2.   

    unicode字符集的原因,一个汉字或一个E文字符都是一个unicode字符。
    所以这一段就好好理解了,E文字符和汉字是同等地位,都是一个unicode字符。
      showmessage(copy(ss,1,1));//测             
      showmessage(copy(ss,1,2));//测s 
      showmessage(copy(ss,1,3));//测s试 
      showmessage(copy(ss,1,4));//测s试s 
      showmessage(copy(ss,1,5));//测s试ss 
      showmessage(copy(ss,1,6));//测s试ss 
    这下面几个嘛,原理一样:unicode是双字符的,如果只取其中一个字节,也是按双字节算
    ss从第0个开始,连续1个字符,当然是第一个字“测”
      showmessage(copy(ss,0,1));//测 
    ss从第1个开始,连续1个字符,当然也是第一个字“测”
      showmessage(copy(ss,1,1));//测 
    ss从第0个开始,连续2个字符,当然还是第一个字“测”
      showmessage(copy(ss,0,2));//测 
      

  3.   

    偶用D很多年了,现在也在用Delphi2009
      

  4.   

    了解下Unicode编码方面的知识就好了
      

  5.   

    ss := '测s试ss'; showmessage(copy(ss,1,1));//测 老感觉这样的结果怪怪的。既然认为一个汉字或一个E文字符都是一个unicode字符,那么“测”是一个字符,“s”也是一个。那从第一个字符开始拷贝,测是第0位,s就是第1位啊。应该结果就是s啊。为什么又变成测了。这样又把“测”当两位了?更乱了。是不是我乱啦~~~~~~~~~~~~~·
      

  6.   

    楼主基础概念都不懂
    string下标是从1开始的
    你copy 0开始是干嘛?
      

  7.   

    这有什么奇怪的,习惯就好
    VC6默认是单字节的,VS2005默认是双字节的