Subst$
Result = Subst$ ( Pattern , ReplaceString [ , ReplaceString ... ] )
Result = Subst ( Pattern , ReplaceString [ , ReplaceString ... ] )
Replaces substrings
&1,
&2, etc. in a pattern with the first, second, and subsequent
ReplaceString argument respectively, and returns the result.
If
Pattern is null, then a null string is returned.
For C developers, this is not unlike a simplified
sprintf.
Example
PRINT Subst("Gambas is a cool &1", "BASIC")
Gambas is a cool BASIC
 |
This function is very useful when you must concatenate strings that must be translated.
Do not use the & operator, as the order of concatenation may change with the language.
For example:
will be translated in french this way:
|
 |
In Gambas 3, if you want to substitute an argument whose index is greater or equal than ten,
you have to enclose the argument index between '{' and '}'.
For example:
DIM aArg AS String[]
PRINT Subst("The 9th argument is &9 and the 10th is &{10}",
aArg[1], aArg[2], aArg[3], aArg[4], aArg[5], aArg[6], aArg[7], aArg[8], aArg[9], aArg[10])
That syntax is not mandatory in Gambas 2, and it was an error. For example, with the '&10' substitution pattern, you cannot make the difference between "substitute the 10th argument" and "substitute the first argument and add a zero".
|