2

I'd to reach a char from a string in corona. Basically I want to:

local mystr = "corona"
print( mystr[3] )

But it always returns nil. How can I achieve that?

Doğancan Arabacı
  • 3,934
  • 2
  • 17
  • 25
  • possible duplicate of [how to iterate individual characters in Lua string?](http://stackoverflow.com/questions/829063/how-to-iterate-individual-characters-in-lua-string) – Bartek Banachewicz Sep 18 '13 at 10:32

1 Answers1

1

Here is simple logic that I used for the same purpose. Hope this may help you:

local mystr   = "corona"
local str_tbl = {}
for i=1,string.len (mystr) do
    str_tbl[i] = mystr:sub(i, i)
    print("Character in position "..i.."is:"..str_tbl[i])
end
Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
Krishna Raj Salim
  • 7,331
  • 5
  • 34
  • 66