From Clomosy Docs
function QuotedStr(const S: string): string;
It encloses a string in single quotes (') and escapes any existing single quotes within the string by doubling them. This is particularly useful when a string is to be used as a constant in an SQL query or another language, ensuring that the string is safely quoted.
Usage:
- QuotedStr takes a string and surrounds it with single quotes.
- If the string already contains single quotes, they are doubled, making it a valid constant in languages like SQL.
Example
TRObject Syntax
var
originalStr, quotedStr: string;
{
originalStr = 'O''Reilly'; // O'Reilly is a common example with an apostrophe
quotedStr = QuotedStr(originalStr);
ShowMessage(quotedStr); // Output: 'O''Reilly'
}
Base Syntax
var originalStr, quotedStr: string; begin originalStr := 'O''Reilly'; // O'Reilly is a common example with an apostrophe quotedStr := QuotedStr(originalStr); ShowMessage(quotedStr); // Output: 'O''Reilly' end;