How to replace a certain index in a string?

Ok so let’s say I have a string that reads “1234” how would it be possible, to get the 4th index (aka the one that says 4) and replace it with let’s say 5, for example.
I’ve looked at the string page but I’m still confused and can’t find any way on how to do this.

You could use string.sub to get the other parts of the string.
In your example you could get the 1st to 3rd index substring of the string, and concatenate it with the replacement (in your example "5") then if there’s one, concatenate it with 5th index to the last index substring of string.

1 Like

Quick way to do so would be the following.

local SplitString = string.split(DesiredString, "")
SplitString[4] = "5"

local NewString = ""
for _, StringSegment in pairs(SplitString) do
    NewString = NewString .. StringSegment
end
1 Like