C#查找替换字符串

C#查找替换字符串,最近练习C#从网上找的代码,使用foreach语句遍历输出,使用Lambda表达式查找数组中包含“C#”的字符串,使用foreach语句遍历输出。

 1 static void Main(string[] args)
 2 {
 3     //声明一个数组并初始化
 4     //code by www.srcfans.com
 5     string[] strLists = new string[] { "明日科技", "C#编程词典", "C#范例大全" };
 6     Console.WriteLine("源字符串数组:");
 7     //使用foreach语句遍历输出
 8     foreach (string str in strLists)
 9     {
10         Console.Write(str + "  ");
11     }
12     Console.WriteLine("\n");
13     //使用Lambda表达式查找数组中包含“C#”的字符串
14     string[] strList = Array.FindAll(strLists, s => (s.IndexOf("C#") >= 0));
15     Console.WriteLine("查找到的包含“C#”的字符串:");
16     //使用foreach语句遍历输出
17     foreach (string str in strList)
18     {
19         Console.Write(str + "  ");
20     }
21     Console.ReadLine();
22 }

 

posted @ 2017-05-22 19:55  jianghuluanke  阅读(1079)  评论(0编辑  收藏  举报