String formatting

From Adventure Game Studio
Revision as of 12:20, 1 December 2005 by *>SSH
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Here are more format flags:

//add leading zeros (up to 4) if necessary:
cJack.Say("The new code is %04d", GetGlobalInt(99));
// (number) = Create a field (number) characters wide:
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
// 0 = Field is padded with 0's instead of blanks:
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
// (blank) = Positive values begin with a blank:
Display("Here comes % d a test", 22); //=> Here comes  22 a test

Character to mask % symbol in strings: %

Display("The %% is the percent symbol.");

Character to mask quotemarks in strings: \

Display("The \" is a quotemark.");

Character for line breaks in strings: [

Display("The [ is a line break.");

Character to mask [ in strings: \

Display("The \[ is a left brace.");