你得到的字符串是包含非打印字符的字符串的有效符号。但是,在使用字符串列表或StringChangeEx
函数时,您不必担心会丢失任何字符。让我说服你这个简短的脚本:
[Code]
const
PrintableString = 'string-string-string-string';
NonPrintableString = 'string'#10#9#9#9'string'#10#9#9#9'string'#10#9#9#9'string';
procedure InitializeWizard;
var
S: string;
StringList: TstringList;
begin
StringList := TstringList.Create;
try
StringList.Add(NonPrintableString);
S := StringList[0];
if S = NonPrintableString then
MsgBox('String list didn''t lose non printable chars!', mbInformation, MB_OK);
StringChangeEx(S, #10#9#9#9, '-', True);
if S = PrintableString then
MsgBox('String has been modified as expected!', mbInformation, MB_OK);
finally
StringList.Free;
end;
end;
不过,我认为只是因为你希望将这些数据提供给用户的问题已经提出,而且有时可能与非打印字符困难。所有的例子。如果你的中间会有一个包含空终止符的字符串,并且你希望向用户显示这样的字符串,例如在消息框中,您将只显示该终止符之前的字符串部分。但是,这不是你可以影响的东西。这是Windows的API函数调用它的背后是多么将字符串:
[Code]
procedure InitializeWizard;
var
S: string;
begin
S := 'Hello'#0' world!';
MsgBox(S, mbInformation, MB_OK);
end;
正如你所看到的,对于上述情况,有必要用一些可打印字符,例如更换空终止字符空间。
它是解决。我使用StringChangeEx(),我替换'#10',这不是一个字符串。对不起,谢谢你的时间。 – MarkOccam