Home > lang > subst 
 fr de es it nl pl pt pt_BR mk sq ca ar fa vi ja ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Refresh  Search  Administration  
Documentation
History
 
Subst$
Syntax
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.

Examples

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:

PRINT Subst(("Today, we are &1 &2"), Format$(Now, "mmm"), Format$(Now, "d"))

will be translated in french this way:

PRINT Subst(("Aujourd'hui, nous sommes le &2 &1"), Format$(Now, "mmm"), Format$(Now, "d"))

3.0In 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".

See also

String Functions