Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to word by word iterate in string in C#?

Tags:

c#

I want to iterate over string as word by word.

If I have a string "incidentno and fintype or unitno", I would like to read every word one by one as "incidentno", "and", "fintype", "or", and "unitno".

like image 358
Partha Avatar asked Sep 18 '09 07:09

Partha


People also ask

How do I iterate over a word in a string?

To iterate over the words in a string: Use the str. split() method to split the string into a list of words. Use a for loop to iterate over the list.

How do you find a word is present in a string in C?

Search for a character in a string - strchr & strrchr The strchr function returns the first occurrence of a character within a string. The strrchr returns the last occurrence of a character within a string. They return a character pointer to the character found, or NULL pointer if the character is not found.


1 Answers

foreach (string word in "incidentno and fintype or unitno".Split(' ')) {
   ...
}
like image 130
Guffa Avatar answered Oct 14 '22 01:10

Guffa