【问题标题】:Using quote inside strings in Delphi [duplicate]在Delphi中使用字符串中的引号[重复]
【发布时间】:2009-02-25 20:45:51
【问题描述】:

可能重复:
How does one escape characters in Delphi string

在 Delphi 中,一个字符串包含在一对 ' 中,但我需要在我的字符串中使用 '... 当我使用一个时,它会结束整个字符串识别。

'inside string ' but this bit is outside' inside again' and the end

是否有一些符号可以消除下一个字符的编码影响?

【问题讨论】:

    标签: string delphi escaping quotes


    【解决方案1】:

    你需要另一个引号来转义一个引号:

    Writeln('I''m in your head'); //prints: I'm in your head
    Writeln(''''); //prints: '
    

    另见this question

    【讨论】:

      【解决方案2】:

      Delphi 有QuotedStr() 函数,可以在字符串周围添加引号并自动转义字符串中的撇号。

      procedure MyForm.MyProc;
      var str : string;
      begin
        str = QuotedStr(MyForm.Edit1);
        ...
      end;
      

      QuotedStr() 会将编辑字段的内容放入撇号。如果编辑字段包含撇号,它们将被正确转义。

      【讨论】:

        【解决方案3】:

        这里有类似的问题:

        How does one escape characters in Delphi string

        涵盖单引号和转义字符

        【讨论】:

          【解决方案4】:

          我通常使用QuotedStr 函数来修复带引号的字符串。此外,我经常发现定义常量如CRLFTAB 分别代表#13#10#9 很有帮助。有时,用引号做类似的事情似乎更清楚(至少对我来说)。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2021-12-17
            • 2013-04-19
            • 2014-02-28
            • 2015-11-29
            • 2012-01-11
            • 2021-12-14
            • 2014-09-26
            • 2013-03-12
            相关资源
            最近更新 更多