1.str = string.format("%0.2f",34.2344) 2.print(str) 输出结果: 1.34.23 更多用法 前面是常用的格式控制符,string.format()还有很多其他的格式控制符,更详细的信息可以参考官方文档。 %c -接受一个数字,并将其转化为ASCII码表中对应的字符 %d, %i -接受一个数字并将其转化为有符号的整数格式 %o -接受...
string.format的基本用法如下: ``` string.format(format, ...) ``` 其中,format为字符串格式化的模板,用于描述格式化字符串的方式;...表示需要格式化的数据,可以是多个参数,每个参数对应一个格式化占位符。 1. 格式化占位符 格式化占位符是用于指定要插入数据的位置和格式的。在string.format中,格式化占位符必须...
函数string.format 用于把字符串格式化输出,用法为 string.format (formatstring, ···) 例子: print(string.format("%s is %d", "ten", 10)) %s 表示字符串,%d 表示数字,它们是 Lua 的格式化输出符号 Pi = 3.1415926 print(string.format("Pi is %.2f", Pi)) 注意:用string.format可以控制一个数据...
local s = string.format('%d%s',123,'freecls') --123freecls s = string.format('%0.2f',1.234343) --1.23(保留2位) --转成16进制,%X为大写的16进制 local s = string.format('%X',140) --8C local s = string.format('%x',140) --8c local s = string.format('%04x',140) --008c...
lua脚本精灵string.format()函数用法string.format()函数的用法lua中有很多字符串操作的函数,string.format()就是其中的一个,顾名思义,format是格式化的意思,则string.format()功能就是格式化一个字符串。 我们知道lua中可以用..连接字符串,可以起到一部分格式化字符串的作用,但是如果字符串镊侗撒钻滞伶玉遍敦彦...
下面是一些示例来说明 string.format 的用法: local name = "Alice" local age = 25 local height = 1.65 local formattedString = string.format("My name is %s, I am %d years old and %.2f meters tall.", name, age, height) print(formattedString) -- 输出:My name is Alice, I am 25 year...
LUA脚本精灵STRING.FORMAT()函数的用法
string.char(num) -- 把数字通过ascall译码转化为字符 string.byte(字符) -- 把字符通过ascall译码转化为数字 都是很有用的字符串函数 最后要给大家介绍介绍string.format(),它适用于进行字符串格式化和将数值输出为字符串的强大工具。 有点类似C中的printf()。
前/后填充 string.format(%10s, str) --不够10个字符前面填充相应空格 string.format(%-10s, str) --不够10个字符后面填充相应空格
string.format()函数的用法 lua中有很多字符串操作的函数,string.format()就是其中的一个,顾名思义, format是格式化的意思,则string.format()功能就是格式化一个字符串。 我们知道lua中可以用".."连接字符串,可以起到一部分格式...