C#richtextbox查找和替换 [英] C# richtextbox find and replace
问题描述
以下是我的输入和期待输出
输入
$ b $bක
文本文本文本文本文本文本
文本文本文本文本文本文本
文本文本文本文本文本文本
文本文本文本文本文本文本
文本文本文本文本文本文本
文本文本文本文本文本文本
ග
期望输出
将SAFA>
该我正则表达式查找和替换编码<预郎= C#> richTextBox2.Text = richTextBox2.Text.Replace ( ක([^] *)ග, < safa>);
我的问题是,当我在记事本++中使用这个正则表达式时,它正在工作并且完全被替换,但是在这里C#,替换不起作用,请指教
什么我试过了:
这是我的正则表达式找到并替换鳕鱼ING <预郎= C#> richTextBox2.Text = richTextBox2.Text.Replace(<跨度类= 代码串> 跨度> <跨度类= 代码串>ක([^] * )ග, < safa>);
您正在调用String.Replace
方法,但必须调用 Regex.Replace方法(字符串,字符串)(System.Text.RegularExpressions) [< a href =https://msdn.microsoft.com/en-us/library/xwewhkd1%28v=vs.110%29.aspx\"target =_ blanktitle =New Window> ^ ] :
正则表达式rgx = 新正则表达式( ක([^] *)ග);
string result = rgx.Replace(richTextBox2.Text, < SAFA> 中跨度>);
richTextBox2.Text = result;
< / safa >
我找到了解决方案。谢谢
string replacementString = Regex.Replace(richTextBox1.Text , ක([^ග] *)ග, @ < safa>);
richTextBox1.Text = replacementString;
Below is my input and expecting output
Input
ක
text text text text text text
text text text text text text
text text text text text text
text text text text text text
text text text text text text
text text text text text text
ග
Expecting Output
<safa>
This is my regex find and replace coding
richTextBox2.Text = richTextBox2.Text.Replace("ක([^]*)ග", "<safa>");
My problem is, when I'm using this regex patter in notepad++ it's working and perfectly replaced, but here C#, replace is not working, please advise
What I have tried:
This is my regex find and replace coding
richTextBox2.Text = richTextBox2.Text.Replace("ක([^]*)ග", "<safa>");
You are calling theString.Replace
method but you must call the Regex.Replace Method (String, String) (System.Text.RegularExpressions)[^]:
Regex rgx = new Regex("ක([^]*)ග"); string result = rgx.Replace(richTextBox2.Text, "<safa>"); richTextBox2.Text = result; </safa>
I found the solution. Thank you
string replacedString = Regex.Replace(richTextBox1.Text, "ක([^ග]*)ග", @"<safa>"); richTextBox1.Text = replacedString;
这篇关于C#richtextbox查找和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!