How to iterate individual characters in Lua string?

后端 未结 6 1409
陌清茗
陌清茗 2020-12-12 18:43

I have a string in Lua and want to iterate individual characters in it. But no code I\'ve tried works and the official manual only shows how to find and replace substrings :

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 19:32

    If you're using Lua 5, try:

    for i = 1, string.len(str) do
        print( string.sub(str, i, i) )
    end
    

提交回复
热议问题