I have a long string. Within this string, there are strings I want to parse. After parsing, I pass the values to a listview. It´s already working, but I have struggles with one String.. Here is a picture:
Here you can see, that the second value is wrong
I am using this string:
UserToken:8VE91632C25166906Amount:5.00Accounts:10buyTime:2018-02-20 12:16:56untilTime:2018-03-22 12:16:56EndBREAKUserToken:2BB32950CL297560CAmount:25.00Accounts:50buyTime:2018-02-21 13:05:52untilTime:2018-03-23 13:05:52EndBREAKUserToken:8S034548J4871372YAmount:30.00Accounts:60buyTime:2018-02-21 15:26:28untilTime:2018-03-23 15:26:28EndBREAKUserToken:84692313143307443Amount:60.00Accounts:120buyTime:2018-02-22 11:33:54untilTime:2018-03-24 11:33:54EndBREAKUserToken:3JJ04496CB952290AAmount:30.00Accounts:60buyTime:2018-02-23 19:28:42untilTime:2018-03-25 19:28:42EndBREAKUserToken:9K197884LF5914344Amount:60.00Accounts:120buyTime:2018-02-27 17:07:16untilTime:2018-03-29 17:07:16EndBREAKUserToken:28C99011N17519701Amount:135.00Accounts:180buyTime:2018-03-05 09:00:00untilTime:2018-04-05 09:00:00EndBREAKUserToken:0TD98762R1733752EAmount:225.00Accounts:300buyTime:2018-03-07 19:00:00untilTime:2018-04-07 20:00:00EndBREAK
This is the way how I parse the values:
Dim words() As String
Dim space() As Char = {"BREAK"}
words = STRINGABOVE.Split(space)
Dim word As String
For Each word In words
Try
Dim sSource As String = word
Dim sDelimStart As String = "UserToken:"
Dim sDelimEnd As String = "Amount:"
Dim nIndexStart As Integer = sSource.IndexOf(sDelimStart)
Dim nIndexEnd As Integer = sSource.IndexOf(sDelimEnd, nIndexStart + sDelimStart.Length + 1)
Dim sDelimStart2 As String = "Amount:"
Dim sDelimEnd2 As String = "Accounts:"
Dim nIndexStart2 As Integer = sSource.IndexOf(sDelimStart2)
Dim nIndexEnd2 As Integer = sSource.IndexOf(sDelimEnd2, nIndexStart2 + sDelimStart2.Length + 1)
Dim sDelimStart3 As String = "Accounts:"
Dim sDelimEnd3 As String = "buyTime:"
Dim nIndexStart3 As Integer = sSource.IndexOf(sDelimStart3)
Dim nIndexEnd3 As Integer = sSource.IndexOf(sDelimEnd3, nIndexStart3 + sDelimStart3.Length + 1)
Dim sDelimStart4 As String = "buyTime:"
Dim sDelimEnd4 As String = "untilTime:"
Dim nIndexStart4 As Integer = sSource.IndexOf(sDelimStart4)
Dim nIndexEnd4 As Integer = sSource.IndexOf(sDelimEnd4, nIndexStart4 + sDelimStart4.Length + 1)
Dim sDelimStart5 As String = "untilTime:"
Dim sDelimEnd5 As String = "End"
Dim nIndexStart5 As Integer = sSource.IndexOf(sDelimStart5)
Dim nIndexEnd5 As Integer = sSource.IndexOf(sDelimEnd5, nIndexStart5 + sDelimStart5.Length + 1)
Dim res As String = Strings.Mid(sSource, nIndexStart + sDelimStart.Length + 1, nIndexEnd - nIndexStart - sDelimStart.Length)
Dim res2 As String = Strings.Mid(sSource, nIndexStart2 + sDelimStart2.Length + 1, nIndexEnd2 - nIndexStart2 - sDelimStart2.Length)
Dim res3 As String = Strings.Mid(sSource, nIndexStart3 + sDelimStart3.Length + 1, nIndexEnd3 - nIndexStart3 - sDelimStart3.Length)
Dim res4 As String = Strings.Mid(sSource, nIndexStart4 + sDelimStart4.Length + 1, nIndexEnd4 - nIndexStart4 - sDelimStart4.Length)
Dim res5 As String = Strings.Mid(sSource, nIndexStart5 + sDelimStart5.Length + 1, nIndexEnd5 - nIndexStart5 - sDelimStart5.Length)
ListView1.Items.Add(New ListViewItem({res, res2, res3, res4, res5}))
Catch
End Try
Next
The result of the second string I parse is always "7560C", so it´s only a part of the string.. The other values are correct. Also, when I set this string to another string like "8VE91632C25166906" its showing me the whole String. Also with regex i can´t get the full string.. Where is the problem? This drives me crazy..
Best regards..