How can i remove the digits from my string?

I want to remove the last 2 digits from this string and i can’t find out which method to use anymore. I already tried string:Sub() but that removes the first digits.

local function Corrected_String(String)
    -- the string is: 00:01:00 and i want to remove the last 00
    return String:sub(4) -- Problem here. 
end

local function Game_Time(DT)
    --// HANDLER //--
    Lighting.ClockTime += (MinutesPerSecond / 60) * DT
    Variables_Folder.Time.Value = Corrected_String(Lighting.TimeOfDay)
end

Help would be appreciated. :grinning:

The first number string.sub takes is the start, so in your case it would be 1, and it also takes a 2nd number, the character to finish at, so you can put -4 (4 characters from the end of the string) there.

1 Like

Can’t you seperate the string into tables using the colons? Then the third index would be the string you want to remove. So then you can use table.remove, and the last two zeroes are gone. (Hope this was helpful and the results are what you wanted.) :grinning:
To split it, you would use something like this:
string:split(“:”)

string.sub("00:01:00", 4, 10)

And

string.sub("00:01:00", -10, -4)

I think one of these is what your looking for. Hope I helped.

1 Like

Just tested it out, it worked for me.

local function Corrected_String(String)
	return string.sub(String, 4, 10)
end


print(Corrected_String("00:01:00"))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.