Search code examples
stringdelphidouble-quotes

In Delphi is there a double quote string function?


I'm aware of the QuotedStr function, but is there a similar function for double quoting for example

for i := 0 to List.count - 1 do
begin
  List[i] := DoubleQuotedStr(List[i]);
end;

Solution

  • You can use AnsiQuotedStr which accepts a quote character:

    List[i] := AnsiQuotedStr(List[i], '"');
    

    From the documentation:

    function AnsiQuotedStr(const S: string; Quote: Char): string;
    

    ....

    Use AnsiQuotedStr to convert a string (S) to a quoted string, using the provided Quote character. A Quote character is inserted at the beginning and end of S, and each Quote character in the string is doubled.