Delphi 中String、ANSIString、TBytes之间的转换


buffer是tbytes型,temp是string型
temp := string(pointer(buffer));
setlength(temp,length(buffer));
CopyMemory(Pointer(temp), @buffer[0], Length(buffer));

d2007以后

一、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编码

六、PChar转String

用StrPas函数,StrPas(PChar):AnsiString;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM