从字符串中读取单词

时间:2015-07-29 17:04:43

标签: c# string

我有一个包含单词的字符串。例:     string s =" asd qwert 123&#34 ;; 如何用c#中的循环分别从字符串中读取asd qwert和123? Thanx提前

1 个答案:

答案 0 :(得分:2)

如果您使用Split方法,则可以非常轻松地完成此操作:

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.  
}

请查看here