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