首页 > 其他 > 详细

查找字符串出现的位置

时间:2014-04-15 21:12:31      阅读:539      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
protected void Page_Load(object sender, EventArgs e)
       {
           string str = "abcqqqqqabchahhabcaaabcssssdbsssabcaadcsssabc";
           string key = "abc";
           MatchCollection mc;
           Regex r = new Regex(key); // 定义一个Regex对象实例
           mc = r.Matches(str);          
           List<int> matchposition = new List<int>();
           for (int i = 0; i < mc.Count; i++) //在字符串中找到所有匹配
           {
               var s = mc[i].Value; //将匹配的字符串添在字符串数组中
               if (s == key)
               {
                   matchposition.Add(mc[i].Index); //记录匹配字符的位置
               }
           }
           for (int j = 0; j < matchposition.Count(); j++)
           {
               Response.Write(matchposition[j] + "<br />");
           }
       }

  

查找字符串出现的位置,布布扣,bubuko.com

查找字符串出现的位置

原文:http://www.cnblogs.com/xffy1028/p/3665177.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!