Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one escape characters in Delphi string

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

like image 805
Boaz Avatar asked Nov 19 '08 16:11

Boaz


People also ask

How do you escape characters in a string?

To insert characters that are illegal in a string, use an escape character. An escape character is a backslash \ followed by the character you want to insert.

How do you implement an escape character?

In you simple language where all variables are single letters, a " replacement pattern" might simply be a $ followed by a character. Once you find the pattern, you then figure out which variable to replace it with. After the replacement, you carry on with the rest of the template string.

How do you escape a string in a shell?

Escape characters. Escape characters are used to remove the special meaning from a single character. A non-quoted backslash, \, is used as an escape character in Bash. It preserves the literal value of the next character that follows, with the exception of newline.


2 Answers

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  

or just

str := 'Newline'#13#10 

Of course, using the platform-dependent constant for newline is better.

like image 60
Jamie Avatar answered Sep 23 '22 22:09

Jamie


To answer the last part of the question, you can use

#$0000    

To add U+0000

This way you can add the other Unicode chars too. (Be sure to use a font that can display those characters.)

like image 31
Toon Krijthe Avatar answered Sep 24 '22 22:09

Toon Krijthe