获取下一个相同字符的索引

编程入门 行业动态 更新时间:2024-10-10 23:22:20
本文介绍了获取下一个相同字符的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个这样的文件:某事,某事,某事,某事,某事"

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; }

更多推荐

获取下一个相同字符的索引

本文发布于:2023-11-30 09:46:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   索引

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!