2013-01-23 52 views
1

對不起,所有這些問題,我一直在問。總之我的問題是 我正確地將值轉換爲字符串?(不是一個unincode字符串)。複製零終止原始字節緩衝區到字符串

const 
address:dword=$0057B568; 
var 
a:string; 
len,i:dword; 
begin 
len:=0; 
repeat 
inc(len); 
until ((pbyte(address+len)^=0));//and(pbyte(address+1)^=0));(for unincode) 

for I:=0 to len do 
a:=a+chr(pbyte(address+I)^); 
//stringreplace(a,#0,'',[rfreplaceall,rfignorecase]); 
MessageBox(0,pchar(a),'',0); 
end. 
+0

雖然0結尾的字符串ü可以使用類型轉換爲羅布下面指出的,我建議ü也瞭解以下標準程序:移動,SetLength,的SetString –

+4

代碼縮進是非常重要的。你應該使用縮進。 –

回答

8

不,這是不正確的。代碼關閉一個字節。首先,通過忽略第一個字節,假定字符串至少有一個字符長。接下來,它複製一個額外的字節。您的代碼可以大大簡化:

a := PAnsiChar(address); 
+1

Sicne他的代碼也顯示了unicode緩衝區的痕跡,我會加上你的答案PWideChar和PAnsiChar以及AnsiString和UnicodeString/WideString –