I'm separating lines of data it into key/value pairs. I have a regex to do this, but I'd like to expand it to be able to parse values with spaces.
So if I have a line consisting of...
A=1 B=2 C=3 + 3 4=NOTHING 5=SOMETHING ELSE
My dictionary would be...
A,1
B,2
C,3
4,NOTHING
5,SOMETHING
I'd like the dictionary to be...
A,1
B,2
C,3 + 3
4,NOTHING
5,SOMETHING ELSE
Code:
Shared Sub ByDelimiter(ByVal input As String, ByRef dict As Dictionary(Of String, String))
If String.IsNullOrEmpty(input) Then
Throw New ArgumentNullException("input")
End If
If dict Is Nothing Then
Throw New ArgumentNullException("dict")
End If
Dim pattern As String = "(?<key>\S+)=(?<value>\S*)"
For Each m As Match In Regex.Matches(input, pattern)
dict.Add(m.Groups("key").Value, m.Groups("value").Value)
Next
End Sub
So if I have a line consisting of...
A=1 B=2 C=3 + 3 4=NOTHING 5=SOMETHING ELSE
My dictionary would be...
A,1
B,2
C,3
4,NOTHING
5,SOMETHING
I'd like the dictionary to be...
A,1
B,2
C,3 + 3
4,NOTHING
5,SOMETHING ELSE