Jump to content

Recommended Posts

Posted

i some of a converter for my output string...

i have this as a input

(Time formation)

01:10:47 (1m 10s 47ms)

/

72:47:47(1h 12m 47s 47ms )

this is the lengt of the output Formation: 0:00:00.00

so what i want as results like this:

Input: 01:10:47

Output: 0:01:10:47

/

Input: 72:47:47

Output: 1:12:47.47

Posted

And this works also.

Local $sTime = "72:47:8"

Local $sReformatedTime = Execute(StringRegExpReplace($sTime, "(d{0,2}):(d{0,2}):(d{0,2})", _
        'StringFormat("%s:%02s:%02s:%02s", int($1/60), mod($1,60), $2, $3)'))
;or
ConsoleWrite(Execute(StringRegExpReplace($sTime, "(d{0,2}):(d{0,2}):(d{0,2})", _
        'int($1/60) & ":" & StringRight("00" & mod($1,60),2) & ":" & StringRight("00" & $2,2) & ":" & StringRight("00" & $3,2)')) & @LF)

MsgBox(0, "Result", $sReformatedTime) ; 1:12:47:08
Posted (edited)

If your last field represents milliseconds, then shouldn't your desired output be: 01:12:47.047 ?

I'm not sure your output examples, nor the two code examples, correctly display milliseconds.

What you refer to as 47ms in the original post is not .47 seconds (470ms).

Edit: Maybe your input source is actually centiseconds and not milliseconds? I don't know, but something is not Kosher about the OP's description of the problem.

Edited by Spiff59
Posted (edited)

Dim $Input, $split, $iBound, $start, $Output

$Input = "1:02:47:47"
$split = StringSplit($Input,":.")
$iBound = $split[0]

If $iBound = 3 Then
    $split[0] = Floor($split[1]/60)
    $split[1] -= $split[0]*60
    $start = 0
Else
    $start = 1
EndIf

$Output = $split[$start]
For $i = $start +1  To $iBound -1
    $Output &= ":" & $split[$i]
Next
$Output &= "." & $split[$iBound]

MsgBox(0, "Result", $Output) ; 1:02:47.47

Please try to be clear about all the expected results when you ask a question. I know it's sometimes complicated to explain things. Is this any better?

Edited by czardas

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...