<< Click to Display Table of Contents >> Navigation: ThinBASIC Core Language > BuiltIn Functions > String functions > StrFormat$ |
Description
Format a string substituting numeric placeholders with the relative string expressions.
Syntax
s = StrFormat$(sMainString, StringExpression_1 [, StringExpression_2 [, ...]])
Returns
String
Parameters
Name |
Type |
Optional |
Meaning |
sMainString |
String |
No |
Main string to be used as template |
StringExpression_1 |
String |
Yes |
Content of StringExpression_1 will be placed in sMainString substituting placeholder "{1}" (if present) |
StringExpression_2 |
String |
Yes |
Content of StringExpression_2 will be placed in sMainString substituting placeholder "{2}" (if present) |
StringExpression_... |
String |
Yes |
... |
Remarks
Any number of StringExpression_... can be indicated.
Restrictions
See also
Examples
Dim sMainString As String
Dim OutString As String
'----------------------------
sMainString = "Hi all. {1} text is created with new {3} function called {2}"
OutString = StrFormat$(sMainString, "This", "StrFormat$", "thinBasic")
'---Output will be:
' 'Hi all. This text is created with new thinBasic function called StrFormat$'
MSGBOX 0, OutString
'----------------------------
sMainString = "Test with numbers: SIN of {1} is {2}"
OutString = StrFormat$(sMainString, 123, SIN(123))
MSGBOX 0, OutString
'----------------------------
sMainString = "Multiple strings repeated: {1}, {2}, {3}, {2}, {1}"
OutString = StrFormat$(sMainString, "A", "B", "C")
MSGBOX 0, OutString