之间的内容我很新的VS.和C#。这里我有Richtextbox。我想过滤两个词之间的内容。填充在RichTextBox的两个词C#
This is the example way to do my processing. This text is on my Richtextbox
我想在字example
和字之间text
来填充内容。 答案是way to do my processing. This
请帮我做这个使用C#。
之间的内容我很新的VS.和C#。这里我有Richtextbox。我想过滤两个词之间的内容。填充在RichTextBox的两个词C#
This is the example way to do my processing. This text is on my Richtextbox
我想在字example
和字之间text
来填充内容。 答案是way to do my processing. This
请帮我做这个使用C#。
你可以使用正则表达式,或者假设text
是您的RichTextBox的文本,此代码:
string from = "example";
int iStart = text.IndexOf(from) + from.Length;
int iEnd = text.IndexOf("text", iStart);
string result = text.Substring(iStart, iEnd - iStart);
你可以这样做:
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);
我认为这个问题是让文本出来在RichTextBox的,请尝试:
var textRange = new TextRange(
richTextBox.Document.ContentStart,
richTextBox.Document.ContentEnd);
var text = textRange.Text;
,然后...
'答案'在这里以_example_字开头,并没有得到所有需要的单词 – Marco
@Marco:糟糕,当然是。我正在关注如何从RichTextBox中获取文本的问题。对不起,我的错。要获得正确的子串,您的解决方案是正确的方法。 – WaltiD
它发生在我身上yesyerday :) – Marco