This may seem like a stupid question, but what are the symbols used for string replacement in string.format? can someone point me to a simple example of how to use it?
Lua uses %s in patterns (Lua's version of regular expressions) to mean "whitespace". %s+ means "one or more whitespace characters".
Lua Pattern matching The `gmatch` function gmatch function will take an input string and a pattern. This pattern describes on what to actually get back. This function will return a function which is actually an iterator. The result of this iterator will match to the pattern.
A StringValue is an object whose purpose is to store a single Lua string. The length of the string can't be more than 200,000 characters (this will cause a “String too long” error). Like all “-Value” objects, this single value is stored in the Value property.
string.format in Lua follows the same patterns as Printf in c:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
There are some exceptions, for those see here:
http://pgl.yoyo.org/luai/i/string.format
Chapter 20 of PiL describes string.format
near the end:
The function
string.format
is a powerful tool when formatting strings, typically for output. It returns a formatted version of its variable number of arguments following the description given by its first argument, the so-called format string. The format string has rules similar to those of theprintf
function of standard C: It is composed of regular text and directives, which control where and how each argument must be placed in the formatted string.
The Lua Reference says:
The format string follows the same rules as the
printf
family of standard C functions. The only differences are that the options/modifiers*
,l
,L
,n
,p
, andh
are not supported and that there is an extra option,q
.
The function is implemented by str_format()
in strlib.c
which itself interprets the format string, but defers to the C library's implementation of sprintf()
to actually format each field after determining what type of value is expected (string or number, essentially) to correspond to each field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With