Mark Bakelaar
asked on
How to split a string on 2 chars, but only store one of them in a string array
Dear experts,
I have the following string
username1#date1,username2# date2,user name3#date 3
I would like to split the string on , and #, but only store the usernames in a string array. How can I do this best.
Thanks for any help,
MB
I have the following string
username1#date1,username2#
I would like to split the string on , and #, but only store the usernames in a string array. How can I do this best.
Thanks for any help,
MB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also Split() using both characters at the onset, and then only use the even numbered items:
Dim Users As New List(Of String)
Dim data As String = "username1#date1,username2#date2,username3#date3"
Dim values() As String = data.Split("#,".ToCharArray) ' <-- split on both # and ,
For i As Integer = 0 To values.GetUpperBound(0) Step 2
Users.Add(values(i))
Next
For Each UserName As String In Users
Debug.Print(UserName)
Next
ASKER