如何反向查找文本 [英] How to find text in reverse

查看:108
本文介绍了如何反向查找文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我已经在c#中创建了一个编辑器.
我的问题是:-
1.如何从头到尾查找文本?
2.如何显示当前行号?

Hi all,
I have created an editor in c#.
My problem is:-
1. how to find text in down to up?
2. how to show current line no?

推荐答案

有两种方法:从蛮力和无知方法开始(使用String.Reverse然后搜索前进)到稍微容易一些的 string.LastIndexOf [
There are a couple of ways: from the brute-force-and-ignorance approach (use String.Reverse and then search forwards) to the slightly easier string.LastIndexOf[^] method. The latter works from a index backwards, so will probably work fine.

It is the same with line numbers: String.Split(''\n'') will break it into lines, or you could count them.

A lot of this will depend on how you are storing your data, displaying your data, and so forth. Over to you!


您要在控件中使用RichTextBox吗?

如果您的表单包含richtextbox,请执行以下操作.
Are you using RichTextBox in your control?

If your form contains richtextbox, then do like this.
private void SearchBackwards(string searchtext)
{
//you wont require to create new instance of richtextbox 
//if the richtext box is not created dynamically
Richtextbox obj = new Richtextbox(); //creating new instance of richtextbox
String mysearchtext= searchtext; //whatever you want to find
int index =0; //this will give you the index of your searchtext in richtextbox
int startindex =0;
index = obj.Find(mysearchtext, 0, startindex, RichTextBoxFinds.Reverse); 
startindex =index; //startindex will be set to current index


}
这应该可行.


}
This should work.


这篇关于如何反向查找文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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