[转]delphi2010 string、ansistring及Tbytes之间的转换
一、string转为ansistring
1、直接赋值 (有警告)
2、ansistring()类型强制转换。(无警告)
二、ansistring 转为string
1、直接赋值 (有警告)
2、string()类型强制转换。(无警告)
三、string 转为Tbytes
1、bytes:= bytesof(str) 已转为ansi编码
2、bytes:= widebytesof(str) UNICODE 编码
四、ansistring 转为Tbytes
1、bytes:= bytesof(str) ansi编码
2、bytes:= widebytesof(string(str)) UNICODE 编码
五、Tbytes 转为string
1、 str:=stringof(bytes) Tbytes 为ansi编码
2、 str:=widestringof(bytes) Tbytes 为unicode编码
ansistring中一个汉字为2的长度, UNICODE中一个汉字为1的长度.
在delphi7中UNICODE中一个汉字为2的长度.
所以长度不一致的情况下请转换为ansistring
浙公网安备 33010602011771号