在 Lua 中,我们要连接两个字符串可以使用 ..
运算符。
str1..str2..str3
参数 | 描述 |
---|---|
str1 | 要连接的字符串 |
str2 | 要连接的字符串 |
str3 | 要连接的字符串 |
返回连接后的字符串。
使用 ..
,实现字符串连接
#!/usr/bin/lua
print("haicoder(www.haicoder.net)\n")
str1 = "Hello"
str2 = "HaiCoder"
res = str1 .. " " .. str2
print(string.format("res = %s", res))
程序运行后,控制台输出如下:
我们使用了 ..
实现了三个字符串的连接。
在 Lua 中,我们要连接两个字符串可以使用 ..
运算符。