string.format

From Garry's Mod
Revision as of 11:02, 23 December 2013 by Humility (Talk | contribs)
Jump to: navigation, search
 string.format( )

Contents

Description

Formats the specified values into the string given.

Arguments

string format

The string to be formatted.

Arguments

any formatParameters

Values to be formatted into the string.

Returns

string

formattedString

Examples

Example

Example showing different types of format codes

s = "Hello World!"

// string
print( string.format("here's a string: %s", s ) )

//string with quotes
print( string.format("here's a quoted string: %q", s ) )

//characters from numeric values
print( string.format("%c%c%c", 65, 66, 67 ) )

//number with an exponent
print( string.format("%e, %E", math.pi, math.pi ) )

// float and compact float
print( string.format("%f, %G", math.pi, math.pi ) )

// signed, signed, and unsigned int
print( string.format("%d, %i, %u", -100, -100, -100 ) )

//octal, hex, and uppercase hex
print( string.format("%o, %x, %X", -100, -100, -100 ) )


Personal tools
Navigation