gpt4 book ai didi

Lua 中的字符串操作 : Swap characters in a string

转载 作者:行者123 更新时间:2023-12-02 06:36:02 25 4
gpt4 key购买 nike

我正在尝试在 Lua 中执行一个函数来交换字符串中的字符。
有人可以帮我吗?

这是一个例子:

Input =  "This LIBRARY should work with any string!"  
Result = "htsil biaryrs ohlu dowkrw ti hna ytsirgn!"

注意:空格也被交换了

非常感谢:)

最佳答案

最简单明了的解决方案是这样的:

Result = Input:gsub("(.)(.)","%2%1")

关于Lua 中的字符串操作 : Swap characters in a string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18882434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com