Reputation: 44648
Basically, I want to be able to use string.Split(char[])
without actually defining a char array as a separate variable. I know in other languages you could do like string.split([' ', '\n']);
or something like that. How would I do this in C#?
Upvotes: 4
Views: 2292
Reputation: 74116
you can use this overload:
public String [] Split(params char [] separator)
like this:
yourstring.Split(' ', '\n')
Upvotes: 1
Reputation: 128317
Here's a really nice way to do it:
string[] s = myString.Split("abcdef".ToCharArray());
The above is equivalent to:
string[] s = myString.Split('a', 'b', 'c', 'd', 'e', 'f');
Upvotes: 8
Reputation: 29476
It's not pretty, but: string.Split(new char[] { ' ', '\n' });
Upvotes: 1