Need Split(' ') to work with one OR MORE spaces

Posted on 2009-12-17
Last Modified: 2013-12-17
I have a string that's space delimited. But when there are two or more spaces between valid pieces of data, it's not working.

I need one, two, three or more spaces to be delimeters.

What call to Split() would handle this?

Question by:newbieweb
    LVL 25

    Expert Comment

    by:Ron M
    The best way to handle that is to do a .replace("  "," ")... before the split, that way you are counting double spaces as a single delimiter.  You can do this without affecting the original string.
    LVL 25

    Expert Comment

    by:Ron M
    In, it might look something like this...
    dim strtempvar as string = (stryourstring.tostring.replace("  "," ").tostring).tostring.split(" ").GetValue(0).tostring

    Author Comment

    Yes, but then I need to loop to be sure al double spaces are replaced. Right?
    LVL 9

    Accepted Solution

               str.Split(new char{' '}, StringSplitOptions.RemoveEmptyEntries);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now