I was hoping i could do it in one line with a regular expression
rather than creating a function that splits it and searches for
specific things.
Anybody got any example regular expressions i could use?
I am by no means a Regex expert - I am simply a man with Expresso.
http://www.ultrapico.com/Expresso.htm
But the following may do what you need:
//////////////////////////
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim dateString As String = "1w 2d 3h 15m"
'// These will throw an InvalidCastException if no match is
found.
'// You could use Regex.IsMatch or Integer.TryParse to check
'// the string value before casting into an integer.
Dim week As Integer = CInt(Regex.Match(dateString, "(?<Week>
\d{1,}(?=w))").Value)
Dim day As Integer = CInt(Regex.Match(dateString, "(?<Day>
\d{1,}(?=d))").Value)
Dim hour As Integer = CInt(Regex.Match(dateString, "(?<Hour>
\d{1,}(?=h))").Value)
Dim minute As Integer = CInt(Regex.Match(dateString, "(?
<Minute>\d{1,}(?=m))").Value)
Console.WriteLine("The Week is {0}", week.ToString())
Console.WriteLine("The Day is {0}", day.ToString())
Console.WriteLine("The Hour is {0}", hour.ToString())
Console.WriteLine("The Minute is {0}", minute.ToString())
Console.Read()
End Sub
End Module
/////////////////////////
Thanks,
Seth Rowe