0

I want to parse this string: "2.8\r\n2.52\r\n" to just get 2.8 and 2.52. How can I go about doing something like this? I tried to using .Split() but I'm not sure what to pass as parameters to get what I am looking for.

salpenza
  • 37
  • 7

2 Answers2

4

String.Split should work fine:

string[] res = "2.8\r\n2.52\r\n".Split("\r\n", StringSplitOptions.RemoveEmptyEntries); // array with {"2.8", "2.52"}
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
2

You need to split by Environment.NewLine which in here would be \r\n

var result = "2.8\r\n2.52\r\n".Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

Edit: Environment.NewLine depends on your environment as you can guess so to be on the safe side you can also use the exact string (\r\n) as a delimiter.

Arin Ghazarian
  • 5,105
  • 3
  • 23
  • 21