首页 > 其他 > 详细

indexof

时间:2018-11-03 22:23:20      阅读:154      评论:0      收藏:0      [点我收藏+]
string msg = "liyifeng";
         //判断这个字符串中出现i的次数,和每次出现的索引位置
             int count = 0;
             string keywords = "i";
           int index = 0;
             while ((index = msg.IndexOf(keywords, index)) != -1) {
                 count++;
                 Console.WriteLine("第{0}次出现【{1}】,索引是:{2}", count, keywords, index);
                  //下次从这个词末的位置开始查找,所以要跳过本次该词的长度个字符位置继续查找
                 index = index + keywords.Length;
            }
             Console.WriteLine("==========================================");
            Console.WriteLine("【{0}】一次一共出现了{1}次。", keywords, count);
Console.ReadLine();

indexof

原文:https://www.cnblogs.com/liyifeng0528/p/9902182.html

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