0

What would be the most elegant way to extract values from a string of comma-separated numbers?

It should account for whitespaces too. Example:

Input string: "22,10,8,13"
Input string: "22, 10, 8, 13"
Input string: "22, 10 ,8 ,13,"

Given all three inputs, the method should recognise the values. Example output for all three inputs: "String contains: 22 10 8 13"

Possible duplicate: Easiest way to parse a comma delimited string to some kind of object I can loop through to access the individual values?

Community
  • 1
  • 1
InvalidBrainException
  • 2,312
  • 8
  • 32
  • 41

1 Answers1

6
string input = "22,10 ,8 , 13";
var output = input.Split(',').Select(i=>i.Trim());
Tarec
  • 3,268
  • 4
  • 30
  • 47