长字串与宽字串


procedure TForm1.Button1Click(Sender: TObject);

var

  s1: AnsiString;  //单字节储存

  s2: WideString;  //双字节储存

begin

  s1 := '万一OK';

  s2 := '万一OK';



  ShowMessage(s1[1]);  //显示乱码

  ShowMessage(s2[1]);  //万



  ShowMessage(IntToStr(Length(s1)));  //6

  ShowMessage(IntToStr(Length(s2)));  //4



  ShowMessage(IntToStr(SizeOf(s1)));  //4

  ShowMessage(IntToStr(SizeOf(s2)));  //4, 其 SizeOf 的大小相同,因为它们只是个指针地址

end;


 
   

你可能感兴趣的:(长字串与宽字串)