Fabmaur
Fabmaur

Reputation: 143

Delphi - Formating a multiple %s string with one argument

When I try to format a string such as '%s%s' using a line of code like so:

format('%s%s', [x]);

I get an exception because you can't have multiple '%s' without using an array with the same amount of arguments such as:

format('%s%s', [x,x]);

However, I don't know how many '%s' I will have to format and therefore I don't know how long the array would have to be. I also only want '%s' assigned to only 1 value.

Is there a way in which you can use multiple '%s' and assign them all to the same index?

Upvotes: 2

Views: 2931

Answers (2)

David Heffernan
David Heffernan

Reputation: 612954

As described in the documentation you can use an index specifier to identify the argument by a zero based index. The index specifier is written immediately after the % and is followed by a :.

Your example would be:

Format('%0:s%0:s', [x])

Upvotes: 8

zeus
zeus

Reputation: 13357

MyStr := StringReplace('%s%s', '%s', x, [rfreplaceALL]);

Upvotes: -2

Related Questions