Search code examples
c#globalization

Why is TextInfo.ListSeparator returned as a string?


Apologies if this has been asked before, but I couldn't find it if it has.

I am currently refactoring some code and removing the hard coded list seperator that I am splitting stuff with.

I am replacing it with TextInfo.ListSeparator from the System.Globalization namespace and noticed that it returns a string rather than a char.

Are there any cultures where more than a single character is used as a list seperator? Or is it completely safe to do something like this:

 line.Split(culture.TextInfo.ListSeparator.First());

Assuming that it will only ever return a string that is one character in length.


Solution

  • Why not avoid the assumption and use something like

    line.Split(new string[] {culture.TextInfo.ListSeparator}, StringSplitOptions.None);