Split a string by word using one or all separators?

Perhaps I just hit the point where i; m overthinking it, but I'm wondering: is there a way to assign a list of special characters that should all be considered delimiters, and then split the string using this list? Example:

"battlestar.galactica-season 1"

must be returned as

battlestar galactica season 1

I think about regex, but at the moment I'm a little excited, looking at him for too long.

EDIT: Thanks guys, confirming my suspicion that I was overdoing this LOL: here's what I ended up with:

//remove the delimiter
            string[] tempString = fileTitle.Split(@"\/.-<>".ToCharArray());
            fileTitle = "";
            foreach (string part in tempString)
            {
                fileTitle += part + " ";
            }

            return fileTitle;

I suppose I could just replace the delimiters with "" spaces ... I will choose the answer as soon as the timer is set!

+5
7

String.Split .

string s = "battlestar.galactica-season 1";
string[] words = s.split('.', '-');
+7

. :

public string[] Split(
    params char[] separator
)
+2

split:

myString.Split(new char[] { '.', '-', ' ' }, StringSplitOptions.RemoveEmptyEntries);

char - .

+2
"battlestar.galactica-season 1".Split(new string[] { ".", "-" }, StringSplitOptions.RemoveEmptyEntries);
+1

, - .

string value = "battlestar.galactica-season 1"

char[] delimiters = new char[] { '\r', '\n', '.', '-' };
    string[] parts = value.Split(delimiters,
                     StringSplitOptions.RemoveEmptyEntries);
    for (int i = 0; i < parts.Length; i++)
    {
        Console.WriteLine(parts[i]);
    }
0

( ) , ( 1 ). :)

,

string title = "battlestar.galactica-season 1".Replace('.', ' ').Replace('-', ' ');
0

URL:

It also includes word division (multiple characters). C # Function Explanation

0
source

All Articles