Search code examples
c#.netpar

Get everything before dot or comma c#


how can I get a substring of everything before dot or comma?

For example:

    string input = "2.1";
int charLocation = text.IndexOf(".", StringComparison.Ordinal);
    string test = input.Substring(0, charLocation );

but what if I have an input = "2,1" ?

I would like to do it in one method, not using twice a substring (once for dot and once for comma)?


Solution

  • string test = input.Split(new Char[] { ',', '.' })[0];