Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I split a string into 2 separate strings?

Asked by
u_jew 0
6 years ago

So pretty much, I need to know how to seperate stuff like this

table = {
    users = {
        "username:password"
    }
}


and just from that, you can print like print('username is username") print('password is password')

1 answer

Log in to vote
3
Answered by
cabbler 1942 Moderation Voter
6 years ago

For one you can make better data structure so you don't have to manipulate strings. There are multiple answers here but patterns are my favorite.

--gets as few characters as possible until colon, then the rest
--parentheses 'capture' matches to give to variables
local user,pass = str:match("(.-):(.+)")

print(user,pass)

Learn more

Ad

Answer this question