Feche1320 Posted May 13, 2011 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 www.host-ar.com.ar
Feche1320 Posted May 13, 2011 Author 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! www.host-ar.com.ar
Aibo Posted May 13, 2011 Posted May 13, 2011 local test = "hello" for i=1, #test do outputChatBox(test:sub(i, i)) end ?
drifterCZE Posted May 13, 2011 Posted May 13, 2011 local test = "hello" for i=1, #test do outputChatBox(test:sub(i, 1)) end
Aibo Posted May 13, 2011 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. ?
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