Using quote inside strings in Delphi [duplicate]

我们两清 提交于 2019-12-19 12:24:57

问题


Possible Duplicate:
How does one escape characters in Delphi string

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.

'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?


回答1:


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.




回答2:


Delphi has QuotedStr() function that adds quotes around string and does escaping of apostrophes in string automatically.

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.




回答3:


Similar Question here:

How does one escape characters in Delphi string

Covers single quotes and escape characters




回答4:


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.



来源:https://stackoverflow.com/questions/587772/using-quote-inside-strings-in-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!