In Delphi 7, how do I escape a percent sign (%) in the Format function?

Blorgbeard is out picture Blorgbeard is out · Nov 6, 2008 · Viewed 9.1k times · Source

I want to do something like this:

SQL.Text := Format('select foo from bar where baz like ''%s%''',[SearchTerm]);

But Format doesn't like that last '%', of course. So how can I escape it? \%? %%?

Or do I have to do this:

SQL.Text := Format('select foo from bar where baz like ''%s''',[SearchTerm+'%']);

?

Answer

Robert Gamble picture Robert Gamble · Nov 6, 2008

Use another % in the format string:

SQL.Text := Format('select foo from bar where baz like ''%s%%''',[SearchTerm]);