Double quote a string that has spaces #225

  temp_str: String;
{ double quote a string that has spaces }
if StrScan(PChar(temp_str), Chr($20)) <> nil then 
  temp_str := AnsiQuotedStr(temp_str, Chr($22));

$20 is the the space character; $22 is the double-quote character.

I know that QuoteSpacedString in the DelphiDabbler Code Snippets Databasedoes the same thing. The above if statement may be faster for strings that can only have $20 as a white space character such as a file path.

Tested on RAD Studio XE3.

Original resource:
Author: Don Rowlett
Contributor: Don Rowlett
Added: 2013/07/30
Last updated: 2013/07/30