string[] Split(char[] separator,StringSplitOptions options)将字符串按照指定的char分割字符串为字符串数组(options取RemoveEmptyEntries的时候移除结果中的空白字符串- string strg = "How are you?Fine,Thank you!";
- char[] removeChar = { ' ', '?', '.', ',','!' };
- string[] word= strg.Split(removeChar,StringSplitOptions.RemoveEmptyEntries);//移除多余的空格
- for (int i = 0; i < word.Length; i++) //遍历查询
- {
- Console.WriteLine(word[i]);
- }
- Console.ReadKey();
复制代码 |