Format string

Syntax

s.format(formatstring ...)
s.formata(formatstring ...)

 

Parts

s - str variable.

formatstring - format-control string.

... - arguments that will be inserted into the formatstring. Number and type of these arguments must match number and type of associated format fields in the formatstring.

 

Remarks

format creates string that can include values of string and numeric expressions. The formatstring consists of ordinary characters, that are copied unchanged, and format fields, that are replaced with values of arguments that follow.

 

formata differs from format only that it writes to the end of s (appends).

 

In Unicode mode, text normally is encoded using UTF-8, where non ASCII characters consist of 2-4 bytes. This and other formatting functions are not aware of this. Don't use format field %c (character) to insert Unicode characters or ANSI characters in range above 127. Read how to do it. Also be careful when using precision with strings that may have non ASCII characters.

 

Tips

The mostly used format fields are %i for integers and %s for strings.

To include variables in format fields, at first format the format-string with these variables. Use %% for %.

To insert this function, can be used the Text dialog from the floating toolbar.

 

Example

str c = "Macrosoftt"
int y = 2003
str s
s.format("Copyright %c %i %s Corporation" 169 y c)
out s ;;Copyright © 2003 Macrosoftt Corporation