C#正则表达式之查找特定的字符!...

 效果截图如下 :



主要代码如下:

 static void Main(string[] args)
        {

            string strTest1 = "{正则表达式-小试牛刀 By yxHuang!...}";
            string strTest2 = "{微软、谷歌、百度}";
            string strTest3 = "{www.BaiDu.com}";

            //在strTest1中寻找yxHuang
            if (System.Text.RegularExpressions.Regex.IsMatch(strTest1,"yxHuang"))
            {
                Console.WriteLine("\n成功在字符串:\t{0}中找到字符串:yxHuang",strTest1);

                
            }

            //在strTest2中寻找:百度
            Regex myRegex = new Regex("百度");
            if(myRegex.IsMatch(strTest2))
            {
                Console.WriteLine("\n成功在字符串:\t{0}中找到字符串:百度", strTest2);

            }

            //在strTest3中,忽略大小写,寻找:baidu
            Regex regexBaidu = new Regex("baidu",RegexOptions.IgnoreCase);
            if (regexBaidu.IsMatch(strTest3))
            {
                Console.WriteLine("\n忽略大小写后,成功在字符串:\t{0}中找到字符串:baidu", strTest3);

                Console.WriteLine("\n2012.04.11 Thursday By yxHuang!...");
                //暂停一下来查看效果
                Console.Read();
            }
        }




posted @ 2012-04-11 20:00  氺〤魚Oo。  阅读(461)  评论(0编辑  收藏  举报