Reputation: 7085
I'm trying to split a song title into two strings- the artist and song. I receive the original string like this: "artist - song". Using this code, I split the string using '-' as the spliiter:
char[] splitter = { '-' };
string[] songInfo = new string[2];
songInfo = winAmp.Split(splitter);
This works fine and all, except when I get to a band with '-' in the name, like SR-71. However, since the original strings are separated with a space then a - and a space again (like SR-71 - Tomorrow), how would I split the string so this happens? I tried changing splitter to a string and inputting
string[] splitter = { " - " };
in it, but it returns that there is no overload match.
Upvotes: 1
Views: 231
Reputation: 25505
You can also use
Match M = System.Text.RegularExpressions.Regex.match(str,"(.*?)\s-\s(.*)");
string Group = M.Groups[1].Value;
string Song = M.Groups[2].Value;
Upvotes: 0
Reputation: 888205
For some reason, string.Split
has no overload that only takes a string array.
You need to call this overload:
string[] songInfo = winAmp.Split(new string[] { " - " }, StringSplitOptions.None);
Don't ask me why.
Upvotes: 2