Delphi字符串中的一个字符如何转义 [英] How does one escape characters in Delphi string
问题描述
Delphi 字符串使用单引号,例如 'a valid string
'.如何在文字字符串中指定 '
字符?如何引用空字节(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
)?
推荐答案
要为字符串添加单引号,请包含两个 '
标记,例如
To add a single quote to a string, you include two '
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屋!