分享

(C#)检索出一个字符串中某字符第n次出现的位置(IndexOf)

 丰收书屋 2017-04-01
           Console.WriteLine("There are total {0} of char '{1}' in your input string.",count,find_c);  
           int index = 0;  
           int n;//第n个find_c  
           Console.WriteLine("Please input the SEQUENCE of the char '{0}' in your input string:", find_c);  
           n = Convert.ToInt32(Console.ReadLine());  
           if (n > count)  
           {  
               Console.WriteLine("Error:The Num must be less than or equal to {0}.",count);  
               Console.ReadKey();  
               return;  
           }  
           for (int j = 1; j <= count; j++)  
           {  
               index = a.IndexOf(find_c,index);  
               if (j == n)  
               {  
                   break;  
               }  
               else  
               {  
                   index = a.IndexOf(find_c,index+1);  
               }  
  
           }  
           Console.WriteLine("The Index of the No.{0} char '{1}' in your input string is {2}.", n, find_c, index);  
           Console.ReadKey();  
       }  
   }   

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多