I have text files that contain time in a strange format which needs to be converted.
The format is:
3 days 14 hours 34 minutes 17 seconds
I want to convert it to 86:34:17 (which will then be able to be manipulated by Excel, etc.)
I have a regEx pattern:
"(\d+\sdays)?(\s?\d+\shours)?(\s?[0-5]?\d\sminutes)?(\s)?[0-5]?\d\sseconds"
The general flow is to read a line of the text from a file, find the pattern that matches, and pass that matched value as a string to a function that converts that time to the simple format and uses it as the replacement value.
This was straightforward in VBScript...
In Visual Basic I am not understanding how I can get the value of the match and pass it to a function in a similar way?
strebor
The format is:
3 days 14 hours 34 minutes 17 seconds
I want to convert it to 86:34:17 (which will then be able to be manipulated by Excel, etc.)
I have a regEx pattern:
"(\d+\sdays)?(\s?\d+\shours)?(\s?[0-5]?\d\sminutes)?(\s)?[0-5]?\d\sseconds"
The general flow is to read a line of the text from a file, find the pattern that matches, and pass that matched value as a string to a function that converts that time to the simple format and uses it as the replacement value.
This was straightforward in VBScript...
Code:
Set re = New RegExp
re.Global = True
myPattern = "(\d+\sdays)?(\s?\d+\shours)?(\s?[0-5]?\d\sminutes)?(\s)?[0-5]?\d\sseconds"
Do While Not objTextFile.AtEndOfStream
s = objTextFile.ReadLine
lineOfText = s
re.Pattern = myPattern
Set objMatch = re.Execute(s)
For Each match In objMatch
lineOfText = re.Replace(s, ConvertToHoursMinsSeconds(match.value))
Next
objCSVFile.WriteLine lineOfText
Loop
In Visual Basic I am not understanding how I can get the value of the match and pass it to a function in a similar way?
strebor