string 在 Delphi 中在字符串中使用引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/587772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using quote inside strings in Delphi
提问by Arthur
Possible Duplicate:
How does one escape characters in Delphi string
可能的重复:
Delphi 字符串中的一个字符如何转义
In Delphi a string is contained within a pair of '
but I need to use '
in my string...
and when I use one it brings a end to the entire string identification.
在 Delphi 中,一个字符串包含在一对中,'
但我需要'
在我的字符串中使用......当我使用一个时,它会结束整个字符串识别。
'inside string ' but this bit is outside' inside again' and the end
Is there some symbol that removes the coding affect of the next character?
是否有一些符号可以消除下一个字符的编码影响?
回答by The_Fox
You need another quote to escape a quote:
您需要另一个引用来转义引用:
Writeln('I''m in your head'); //prints: I'm in your head
Writeln(''''); //prints: '
See also this question.
另请参阅此问题。
回答by zendar
Delphi has QuotedStr()
function that adds quotes around string and does escaping of apostrophes in string automatically.
Delphi 具有QuotedStr()
在字符串周围添加引号并自动对字符串中的撇号进行转义的功能。
procedure MyForm.MyProc;
var str : string;
begin
str = QuotedStr(MyForm.Edit1);
...
end;
QuotedStr()
will put contents of edit field into apostrophes. If edit field contains apostrophes, they will be properly escaped.
QuotedStr()
将编辑字段的内容放入撇号。如果编辑字段包含撇号,它们将被正确转义。
回答by Jamie
Similar Question here:
类似的问题在这里:
How does one escape characters in Delphi string
Covers single quotes and escape characters
涵盖单引号和转义字符
回答by jrodenhi
I usually use the QuotedStr
function to fix strings with quotes in them. Also, I often find it helpful to have defined constants like CRLF
and TAB
that represent #13#10
and #9
respectively. Sometimes, it seems clearer (to me at least) to do something similar with quotes.
我通常使用该QuotedStr
函数来修复带有引号的字符串。另外,我经常发现有帮助的定义的常量一样CRLF
,并TAB
表示#13#10
和#9
分别。有时,用引号做类似的事情似乎更清楚(至少对我来说)。