1
string[] ssss = "1,2,,3".Split(new[] {','})
                  .Where(a=>!string.IsNullOrEmpty(a))
                  .Select();

How does this works?

4 Answers 4

9

You could also use

"1,2,,3".Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
Sign up to request clarification or add additional context in comments.

Comments

3
string[] ssss = "1,2,,3".Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries);

Comments

2
string[] ssss = "1,2,,3".Split(new[] {','}).Where(a=>!string.IsNullOrEmpty(a)).ToArray();

1 Comment

This option is the better choice for .NET Compact Framework as it doesn't accept the same Split signature as .NET Framework.
1
var ssss = "1,2,,3".Split(new[] {','}).Where(a=>!string.IsNullOrEmpty(a));
foreach (string s in ssss)
{
    Console.WriteLine(s);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.