查找字符串并获取字符串在一行中的位置 [英] Find string and get string's position in a line

查看:243
本文介绍了查找字符串并获取字符串在一行中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以计算行中的字符数.我可以使用rtb.Text.IndexOf或rtb.Find来获取字符串在richtextbox中的位置.IndexOf并在任何行中查找字符串.如何查找字符串和获取字符串"在一行中的位置?
计数char的代码行:

I can count number of char in line.I can use rtb.Text.IndexOf or rtb.Find to get string''s position in richtextbox.IndexOf and Find find string in any lines.How to find string and get string''s position in a line?
code for count char in line:

public void CharacterCounter(string line,char fchars)
{
            counter = 0;
            foreach (char c in line)
            {
                if (c == fchars)
                {
                    counter++;
                }
            }
}
//rtb TextChanged
int index = rtb.SelectionStart;
int line = rtb.GetLineFromCharIndex(index);
CharacterCounter(rtb.Lines[line],'b');
label1.Text = string.Format("char  counter: {0}", counter);

推荐答案

使用StringReader获取更多信息,请参考
Use StringReader for more info pls refer http://www.dotnetperls.com/stringreader[^]


这篇关于查找字符串并获取字符串在一行中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆