G.Format

From GMod Wiki

Jump to: navigation, search
Function
Syntax Format( String s, param1, param2, ... )
Where is this used?
Description:
Building a string using format codes in s and the supplied parameters.
Returns: String
Part of Library: Global Functions
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.Format]G.Format [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionExample showing the different types of format codes.
Used onNewerShared.png
Code
s = "Hello, world!"
 
// string
print(Format("here's a string: %s", s))
 
// string with quotes
print(Format("here's a quoted string: %q", s))
 
// characters from numeric values
print(Format("%c%c%c", 65, 66, 67))
 
// number with an exponent
print(Format("%e, %E", math.pi, math.pi))
 
// float and compact float
print(Format("%f, %G", math.pi, math.pi))
 
// signed, signed, and unsigned int
print(Format("%d, %i, %u", -100, -100, -100))
 
// octal, hex, and uppercase hex
print(Format("%o, %x, %X", -100, -100, -100))
Outputhere's a string: Hello, world!

here's a quoted string: "Hello, world!"
ABC
3.141593e+000, 3.141593E+000
3.141593, 3.14159
-100, -100, 4294967196

37777777634, ffffff9c, FFFFFF9C


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox