Feche1320 Posted May 13, 2011 Share Posted May 13, 2011 For example, on C I would do: char test[24] test = "hello" print(test[4]) And if I'm not wrong that will print 'l'. But on lua I tryed that, and seems not to work. How can I do it? Thanks Link to comment
Aibo Posted May 13, 2011 Share Posted May 13, 2011 local test = "hello" print(test:sub(4, 4)) Link to comment
Feche1320 Posted May 13, 2011 Author Share Posted May 13, 2011 But what I need is: test = "hello" outputChatBox(test[1]) -- h outputChatBox(test[2]) -- e outputChatBox(test[3]) -- l outputChatBox(test[4]) -- l outputChatBox(test[5]) -- o Hope you understand me. --EDIT Nevermind, got it, thanks! Link to comment
Aibo Posted May 13, 2011 Share Posted May 13, 2011 local test = "hello" for i=1, #test do outputChatBox(test:sub(i, i)) end Link to comment
drifterCZE Posted May 13, 2011 Share Posted May 13, 2011 local test = "hello" for i=1, #test do outputChatBox(test:sub(i, 1)) end Link to comment
Aibo Posted May 13, 2011 Share Posted May 13, 2011 local test = "hello" for i=1, #test do outputChatBox(test:sub(i, 1)) end second parameter here is not the amount of characters, it is ending position. this way it'll output only "h" and nothing after it. string.sub(s, i [, j])s:sub(i [,j]) Return a substring of the string passed. The substring starts at i. If the third argument j is not given, the substring will end at the end of the string. If the third argument is given, the substring ends at and includes j. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now