I need to split a string into two parts, but I’m horrible at strings…
How would I account for where it splits?
For example, what if the string was “hello how are you doing today?”, how would I split it like
“hello how are”
“you doing today?”
I need to split a string into two parts, but I’m horrible at strings…
How would I account for where it splits?
For example, what if the string was “hello how are you doing today?”, how would I split it like
“hello how are”
“you doing today?”
local str = "hello how are you doing today?"
local splitAt = str:find("you")
print(str:sub(1, splitAt - 1), str:sub(splitAt))
a lot of ways
local str = "hello how are you doing today?"
local splitPoint = 15
local part1 = str:sub(1, splitPoint)
local part2 = str:sub(splitPoint + 1)
print(part1)
print(part2)
local str = "hello how are you doing today?"
local part1, part2 = str:match("^(.-) (you.*)$")
print(part1, part2)
You can use string:find as well.
Ya, I just put up a few. A lot of ways to do that.