开发者

Populate the content in between two words in Richtextbox c#

I am very new to VS. And c#. Here I have Richtextbox. I want to filter it content which in between two words.

This is the example way to do my 开发者_如何学运维processing. This text is on my Richtextbox

I want to populate content in between word example and word text. Answer is way to do my processing. This

Please help me doing this using c#.


You could use RegEx or, assuming text is your richtextbox text, this code:

string from = "example";
int iStart = text.IndexOf(from) + from.Length;
int iEnd = text.IndexOf("text", iStart);
string result = text.Substring(iStart, iEnd - iStart);


You can do like this:

string strTest = 
  "This is the example way to do my processing. This text is on my Richtextbox";
strTest = strTest.Substring(strTest.IndexOf("example") + 8);
strTest = strTest.Substring(0,strTest.IndexOf("text")-1);


I think the problem is to get the text out of the RichTextBox, try:

var textRange = new TextRange(
    richTextBox.Document.ContentStart, 
    richTextBox.Document.ContentEnd);
var text = textRange.Text;

and then...

(see other answers)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜