String formatting: Difference between revisions
no edit summary
*>SSH No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
*Inserting strings: %s | |||
Display("Your name is %s.", player.Name); | |||
*Inserting letters: %c | |||
Display("%c is a letter.", mychar); | |||
or | |||
Display("The first letter of the alphabet is the %c", 'A'); | |||
*Inserting floats: %f | |||
Display("%f is a floating point number.", myfloat); | |||
*Inserting integers: %d | |||
Display("%d is a number.", myint); | |||
===Integer format flags=== | |||
*Creating field (number) characters wide: %(number)d | |||
Display("Here comes %4d a test", 22); //=> Here comes 22 a test | Display("Here comes %4d a test", 22); //=> Here comes 22 a test | ||
*Left justify: - | |||
Display("Here comes %-4d a test", 22); //=> Here comes 22 a test | Display("Here comes %-4d a test", 22); //=> Here comes 22 a test | ||
*Padding field with 0's instead of blanks: 0 | |||
Display("Here comes %04d a test", 22); //=> Here comes 0022 a test | Display("Here comes %04d a test", 22); //=> Here comes 0022 a test | ||
*Sign of number always shown: + | |||
Display("Here comes %+d a test", 22); //=> Here comes +22 a test | Display("Here comes %+d a test", 22); //=> Here comes +22 a test | ||
*Positive values begin with a blank: (blank) | |||
Display("Here comes % d a test", 22); //=> Here comes 22 a test | Display("Here comes % d a test", 22); //=> Here comes 22 a test | ||
==Displaying special characters== | |||
*Character to mask % symbol in strings: % | |||
Display("The %% is the percent symbol."); | Display("The %% is the percent symbol."); | ||
Character to mask quotemarks in strings: \ | *Character to mask quotemarks in strings: \ | ||
Display("The \" is a quotemark."); | Display("The \" is a quotemark."); | ||
Character for line breaks in strings: [ | *Character for line breaks in strings: [ | ||
Display("The [ is a line break."); | Display("The [ is a line break."); | ||
Character to mask [ in strings: \ | *Character to mask [ in strings: \ | ||
Display("The \[ is a left brace."); | Display("The \[ is a left brace."); | ||
[[Category:Tidbits and Snippets]] | [[Category:Tidbits and Snippets]] |