c# split and join two arrays but remove blanks

Posted on 2014-09-03
Last Modified: 2014-09-16
I have a program where a user can select email addresses in a grid and type them into a textbox.  They come in delimited by a semi colon. I split on the semi colon, then union the lists to get an array containing both of the arrays' email addresses.  This works, but if one of the strings starts out empty, I get a blank array entry.  How can I do the same thing, but ignore empty strings?

                string[] tmpCombinedListOfEmailAddresses = inputModel.emailAddresses.Split(';');
                var emailToAddressesWriteInArray = inputModel.emailAddressesWritein.Split(';');
                string[] tmpCombinedArrayOfString = tmpCombinedListOfEmailAddresses.Union(emailToAddressesWriteInArray).ToArray();
Question by:jackjohnson44
    1 Comment
    LVL 39

    Accepted Solution

    Add the RemoveEmptyEntries Option:

    inputModel.emailAddresses.Split(';', StringSplitOptions.RemoveEmptyEntries)
     inputModel.emailAddressesWritein.Split(';', StringSplitOptions.RemoveEmptyEntries);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 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

    18 Experts available now in Live!

    Get 1:1 Help Now