Lua字符串反转reverse函数

Lua字符串反转reverse函数教程

Lua 中 reverse 函数用于反转字符串。

reverse函数详解

语法

string.reverse(arg)

参数

参数 描述
arg 要反转的源字符串

返回值

返回反转后的字符串。

案例

reverse字符串反转

使用 reverse() 函数,实现字符串反转

#!/usr/bin/lua print("haicoder(www.haicoder.net)\n") s = "Hello HaiCoder!" res = string.reverse(s) print("res =", res)

程序运行后,控制台输出如下:

12_Lua字符串反转reverse函数.png

我们使用了 string.reverse 实现了字符串反转。

Lua字符串反转reverse函数总结

在 Lua 中 reverse 函数用于反转字符串。