-2

I have a string which contains words. Example: string s = " asd qwert 123 "; How can I read asd qwert and 123 from the string seperately with a loop in c#? Thanx in advance

Rati Sharabidze
  • 69
  • 1
  • 12

1 Answers1

2

If you make use of the Split method you can do so quite easily:

foreach(var str in s.Split(' '))
{
     // str would be one of asd, qwert and 123
     // since splitting on whitespace gives you an array 
     // with the words in the string s, which are separated one
     // from the other with a whitespace between them.  
}

Please have a look here.

Christos
  • 53,228
  • 8
  • 76
  • 108
  • 1
    The OP might need to use the overload that takes a `StringSplitOptions` and pass in `StringSplitOptions.RemoveEmptyEntries` – juharr Jul 29 '15 at 17:10