Home / lang / subst 
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")
<hr>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 might 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"))

See also

String Functions