LUA string manipulation functions, string formatting

Method
converts uppercase string.upper (argument): string all uppercase letters

Conversion lowercase string.lower (argument): All lowercase string

String replacement string.gsub (mainString, findString, replaceString, num)
replacement in the string, mainString a string to be replaced, findString for the character to be replaced, replaceString to replace characters, replace where num (can be ignored, Alternatively the whole), such as: string.gsub ( "aaaa", " a", "z", 3)
results: zzza

Looking substring string.find (str, substr, [init, [end]]) searches a specified content specified in the target string (the third parameter as an index), and returns its location, does not exist is returned nil.string.find ( "Hello Lua user", "Lua", 1) the result is 79

String inversion string.reverse (arg)
to reverse a string string.reverse ( "Lua") auL
calculated string length string.len (arg) string.len ( "abc ") is 3 Results

The first parameter string formatting functions Lua String.Format () to generate a string having a specific format, the format function, after code corresponding to each of the various data formats.
Here Insert Picture Description
= string1 "the Lua"
string2 = "the Tutorial"
- basic string formatting
print (string.format ( "Basic Format% s% s", string1, string2))

For example: a = 'I'm S%'
C = String.Format (A, 'Yong Zhang Shuai')
Print ©

Published 49 original articles · won praise 3 · Views 5615

Guess you like

Origin blog.csdn.net/nb_zsy/article/details/104254983