guy = {first: "Eric", last: "Cartman"};
NSB.Print("hello {} and {}".format("you", "bob"));
NSB.Print("hello {0} and {1}".format("you", "bob"));
NSB.Print("hello {first} {last}".format(guy));
NSB.Print("hello {0} and {1} and {a}".format("you", "bob", {a:"mary"}));
NSB.Print("hello {0} and {1} and {a} and {2}".format("you", "bob", "jill", {a:"mary"}));
Format: Difference between revisions
Jump to navigation
Jump to search
Created page with "<pre> FORMATCURRENCY(expression[, fractionaldigits[, leadingdigit[, parensfornegative[, groupdigits]]]]) FORMATDATETIME(date[, formatname]) FORMATNUMBER(exp..." |
No edit summary |
||
(31 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
Format(''string'', ''replace0''[,''replace1''...]) | |||
Format(''string'', {replace object}) | |||
== Description == | |||
Replaces {n} placeholders with arguments. One or more arguments can be passed, in addition to the string itself, to insert into the string. Arguments can be three different style: | |||
<ol> | |||
<li>{} Empty brackets. Placeholders are replaced with arguments in the same order as they appear in the function call. | |||
<li>{1] Brackets with a number. Placeholders are replaced by the argument number as it appears in the function call. | |||
<li>{name} Brackets with a name. Placeholders are replaced by the value of the name in the argument object. | |||
</ol> | |||
== Example == | |||
<tabber> | |||
JavaScript= | |||
<syntaxhighlight lang="JavaScript"> | |||
guy = {first: "Eric", last: "Cartman"}; | |||
NSB.Print("hello {} and {}".format("you", "bob")); | |||
NSB.Print("hello {0} and {1}".format("you", "bob")); | |||
NSB.Print("hello {first} {last}".format(guy)); | |||
NSB.Print("hello {0} and {1} and {a}".format("you", "bob", {a:"mary"})); | |||
NSB.Print("hello {0} and {1} and {a} and {2}".format("you", "bob", "jill", {a:"mary"})); | |||
</syntaxhighlight> | |||
|-| | |||
BASIC= | |||
<syntaxhighlight lang="vb.net"> | |||
guy = {first: "Eric", last: "Cartman"} | |||
Print Format("hello {} and {}", "you", "bob") | |||
Print Format("hello {0} And {1}", "you", "bob") | |||
Print Format("hello {first} {last}",guy) | |||
Print Format("hello {0} and {1} and {a}", "you", "bob", {a:"mary"}) | |||
Print Format("hello {0} and {1} and {a} and {2}", "you", "bob", "jill", {a:"mary"}) | |||
</syntaxhighlight> | |||
</tabber> | |||
== Output == | |||
<pre> | |||
hello you and bob | |||
hello you and bob | |||
hello Eric Cartman | |||
hello you and bob and mary | |||
hello you and bob and mary and jill | |||
</pre> | </pre> | ||
[[Category:Language Reference]] | |||
[[Category:Strings]] | |||
[[Category:BASIC Functions]] | |||
Latest revision as of 15:22, 24 July 2019
Format(string, replace0[,replace1...]) Format(string, {replace object})
Description
Replaces {n} placeholders with arguments. One or more arguments can be passed, in addition to the string itself, to insert into the string. Arguments can be three different style:
- {} Empty brackets. Placeholders are replaced with arguments in the same order as they appear in the function call.
- {1] Brackets with a number. Placeholders are replaced by the argument number as it appears in the function call.
- {name} Brackets with a name. Placeholders are replaced by the value of the name in the argument object.
Example
guy = {first: "Eric", last: "Cartman"}
Print Format("hello {} and {}", "you", "bob")
Print Format("hello {0} And {1}", "you", "bob")
Print Format("hello {first} {last}",guy)
Print Format("hello {0} and {1} and {a}", "you", "bob", {a:"mary"})
Print Format("hello {0} and {1} and {a} and {2}", "you", "bob", "jill", {a:"mary"})
Output
hello you and bob hello you and bob hello Eric Cartman hello you and bob and mary hello you and bob and mary and jill