How would I remove everything from a tring after the space like:
local str = "102938 36"
local newString = something(str)
print(str) -- prints: "102938"
How would I remove everything from a tring after the space like:
local str = "102938 36"
local newString = something(str)
print(str) -- prints: "102938"
function something(str)
return string.split(str, " ")[1]
end
It prints nil if I try it and even if I just put in 3248 65
Oops, forgot Luau is 1-indexed
You might also consider using string.match, with the pattern "[^ ]+"
, to retrieve the first series of characters unbroken by a space. Otherwise the pattern "%d+"
would also work fine, if you always anticipate that the first chunk will all be digits.
Alternatively, you can just do :gsub(" ", "")
local Text = "Hello World !!"
local NoSpaces = string.gsub(Text, " ", "")
print(NoSpaces)
--> "HelloWorld!!"
Based on how they worded their post, it seems like they’re only looking for the first chunk of the string before the space.
Yes, thats what I was looking for
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.