so you can do string.split right?
you can do MyString[1] right?
Houw would i go about removing MyString[1]?
So removing the first word in a string
For example
String.Remove(MyString, “DeleteThis”) --(This function was just made up)
Thanks!
I don’t think I am quite understanding, but are you trying to delete a string value or the whole thing?
To delete what’s in the string value do string.Value = ""
To delete the whole string do string:Destroy()
I Don’t think that’s a function in Roblox studio.
i want do do this:
“I Had a Alright Day”
do what i want here
“Had A Alright Day”
do it again
“A Alright Day”
I wanna delete the first word
Alright, to do this do something like this:
Here is an example
-- Function to remove the first word from a string
function removeFirstWord(s)
local words = {}
for word in s:gmatch("%S+") do
table.insert(words, word)
end
table.remove(words, 1)
return table.concat(words, " ")
end
-- Example usage:
local string = "I Had an Alright Day"
-- Remove the first word once
local result1 = removeFirstWord(string)
print(result1) -- Output: "Had an Alright Day"
-- Remove the first word again
local result2 = removeFirstWord(result1)
print(result2) -- Output: "An Alright Day"
-- Remove the first word again
local result3 = removeFirstWord(result2)
print(result3) -- Output: "Alright Day"
You can achieve this by using string.sub
which is a function allowing us to cut strings:
local function removeIndex(s: string, i: number): string
return s:sub(1, i-1)..s:sub(i+1, s:len())
end
print(removeIndex("hello", 1)) --ello
print(removeIndex("world", 4)) --word
could use string.gsub with a string pattern
something like this would probably work idk string patterns are annoying
local newString = string.gsub(targetString, "%w+%s", "", 1)
i forgot to mention i fixed it, there were diffrent if statements to delete diffrent words so i just deleted the first few letters
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.