本文介绍了获取下一个相同字符的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的文件:某事,某事,某事,某事,某事"
I have a file like this: "Something, something, something, something, something"
我想通过以下方式获取第三个,"的索引:
And I want to get the index of third "," with:
StreamReader sr=new StreamReader("File.txt"); string s=sr.Readline(); string c=s.Substring(0, s.IndexOf(','))); 推荐答案抱歉之前的回答,我为你创建了一个函数,试试这个,你需要传递你的字符串、查找字符和出现次数作为参数.这里是一个演示.
Sorry for previous answer, I created a function for you, try this, You need to pass your string, character to find and occurance number as parameters. Here is a demo.
public static int getSpecifiedIndexOf(string str,char ch,int index) { int i = 0,o=1; while ((i = str.IndexOf(ch, i)) != -1) { if(o==index)return i; o++; i++; } return 0; }更多推荐
获取下一个相同字符的索引
发布评论