Jump to content

String.gsub


Recommended Posts

Posted

Hello.

How can i replace dot (".") with ":"? String.gsub doesn't work to me. I converted sec to minutes and i have sth like 1.23 and i want 1:23. Hope u can help me.

Posted

Resolved.

I found this:

function sec2min(sSeconds) 
local nSeconds = tonumber(sSeconds) 
if nSeconds == 0 then 
--return nil; 
return "00:00"; 
else 
nHours = string.format("%02.f", math.floor(nSeconds/3600)); 
nMins = string.format("%02.f", math.floor(nSeconds/60 - (nHours*60))); 
nSecs = string.format("%02.f", math.floor(nSeconds - nHours*3600 - nMins *60)); 
return nMins..":"..nSecs 
end 
end 

Posted

try to convert the sec's and hour's in difrent variable's. (local sec = ,local hour =)

in "String.gsub" the dot "." , as pattern mean's all character's so you will have ":::"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...