How does one escape characters in Delphi string

前端 未结 3 984
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 00:49

Delphi strings use single quotes, for example \'a valid string\'. How does one specify the \' character within a literal string? How would one refe

相关标签:
3条回答
  • 2020-12-10 00:55

    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.

    0 讨论(0)
  • 2020-12-10 01:15

    For ' character put it twice. For example: 'Don''t'. Null byte type as #0.

    0 讨论(0)
  • 2020-12-10 01:16

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

    0 讨论(0)
提交回复
热议问题