• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

c# split and join two arrays but remove blanks

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();
0
jackjohnson44
Asked:
jackjohnson44
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Add the RemoveEmptyEntries Option:

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now