如何在Delphi字符串中转义字符 [英] How does one escape characters in Delphi string
问题描述
Delphi字符串使用单引号,例如有效的字符串。如何指定文字字符串中的字符?如何引用空字节(Unicode代码点U + 0000)?
Delphi strings use single quotes, for example 'a valid string'. How does one specify the ' character within a literal string? How would one refer to the null byte (Unicode code point U+0000)?
推荐答案
要将一个单引号添加到字符串,您包括2'
To add a single quote to a string you include 2 ' marks e.g.
str := '''test string''';
Writeln(str)
在上面的字符串中,您有正常的单引号启动一个字符串然后两个为单引号。字符串的结尾也是一样。
In the string above, you have the normal single quotation to start a string and then two for the single quote. Same goes for the end of the string.
您还可以使用#后跟一个数字用于其他转义字符,例如
对于新行:
You can also use # followed by a number for other escape character e.g.
For a new line:
str := 'Newline' + #13 + #10
或只是
str := 'Newline'#13#10
当然,使用平台依赖的常规为换行更好。
Of course, using the platform-dependent constant for newline is better.
这篇关于如何在Delphi字符串中转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!