ACanadian
asked on
string to timespan
Hi Gurus,
My question is fairly simple I think but I wondering if there is som code already written to do the following.
I would like to convert a string to a time span.
String Examples: 5 Minutes, 1 Hour 10 Minutes, 1 Day 2 Hours 30 Minutes
Is there any code to do this? Or am going to have to parse these strings myself and create the TimeSpan objects.
Thanks in advance
ACanadian
My question is fairly simple I think but I wondering if there is som code already written to do the following.
I would like to convert a string to a time span.
String Examples: 5 Minutes, 1 Hour 10 Minutes, 1 Day 2 Hours 30 Minutes
Is there any code to do this? Or am going to have to parse these strings myself and create the TimeSpan objects.
Thanks in advance
ACanadian
Well, there is a TimeSpan.Parse method, but it's not as flexible as it would need to be to handle the sort of string you mention. I would at the very least parse your strings down to the format this function takes.
ASKER
Thats what I thought I would have to do.
Now pretty have never had to parse strings for any reason. How would you go about it?
Character by character starting at the beginnging of the string?
any digits before characters are stored and then once the characters are found to be either day, hour, minute then store the digits?
I'll try that until I hear differently.
ACanadian
Now pretty have never had to parse strings for any reason. How would you go about it?
Character by character starting at the beginnging of the string?
any digits before characters are stored and then once the characters are found to be either day, hour, minute then store the digits?
I'll try that until I hear differently.
ACanadian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your right I can't do everything, thanks for those functions you listed there.
I'll respond if I have any trouble with that approach.
OK. Good luck.
ASKER
Thanks for the code snippet on splitting up an array... and I call myself a c# coder... sheesh you learn something new everyday :)
You certainly do.