Kalvis
Kalvis

Reputation: 635

How to split string variable by multiple characters

I need to split string variable by multiple characters, in my case by " "; Here is my code:

string s_var = "New   String   variable";
string[] s_mas = s_var.Split("   ");

The Split() method isn't working for me, it says that the argument " " is invalid. Hoping you guys know how to solve this issue.

Upvotes: 0

Views: 96

Answers (1)

Grant Winney
Grant Winney

Reputation: 66439

You're not specifying the correct arguments.

  • If you want to split by a string, you need to specify an array.
  • You also need to specify whether or not to discard empty strings.

Try this:

var s_mas = s_var.Split(new[] { "   " }, StringSplitOptions.None);

Upvotes: 4

Related Questions