[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to split a string on 2 chars, but only store one of them in a string array

Posted on 2012-08-13
Medium Priority
Last Modified: 2012-08-13
Dear experts,

I have the following string

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,
Question by:mark_norge
LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 38287110
You can try following

Dim Users As New List(of string)
ForEach username in strNames.Split(",")
     Users.Add(username.substring(0, username.indexof("#")-1)

Author Closing Comment

ID: 38287254
Thanks a lot!
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38287572
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

        For Each UserName As String In Users

Open in new window


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question