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

Help with string manipulation?

Asked by 7 years ago
Edited by evaera 7 years ago
local mathchoice = math.random(0, 1)
local choices = string.sub(message.content, 8)
local choice0 = string.sub(choices, string.len(string.sub(choices, string.find(choices, " or ")-2)))
local choice1 = string.sub(choices, string.len(choice0))
if mathchoice == 0 then
    choice = choice0
elseif mathchoice == 1 then
    choice = choice1
end
print(mathchoice)
print(choice)

I'm trying to find choice0 then find choice1. The best idea I've had is to find everything up to " or" and remove " or" and everything after it. Once that's done it could be used to find choice1. Any idea on how to make that happen?

1 answer

Log in to vote
0
Answered by
evaera 8028 Trusted Badge of Merit Snack Break Game Jam Winner Moderation Voter Administrator Community Moderator Super Administrator
7 years ago
Edited 7 years ago
local c = math.random(0, 1)
local message = "corndogs or hotdogs"

local conj = message:find(" or ")
local choice = c == 1 and message:sub(1, conj-1) or message:sub(conj+4)
print(choice)
Ad

Answer this question