Jump to content

Loop a string


'LinKin

Recommended Posts

Posted

Hello,

How can I iter character by character of a string?

Like: "This_String_For_Example"

I want to check one by one each character.

Thanks.

Posted

You can use something like this:

function runaString ( str )  
    local len = str:len ( ) 
    for i=0, len-1 do  
        local c = str:sub ( i, i ) 
        -- c = the char 
    end 
end 

Posted

Alternatively, you can use string.gmatch:

local str = "Hello, world" 
  
for c in str:gmatch ( "." ) do 
    outputChatBox ( c ) 
end 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...