views:

877

answers:

4

in delphi a string in contained within a pair of 's 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?

+19  A: 

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.

The_Fox
+4  A: 

Similar Question here:

How does one escape characters in Delphi string

Covers single quotes and escape characters

Jamie
+6  A: 

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.

zendar
+1  A: 

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.