C#richtextbox查找和替换 [英] C# richtextbox find and replace

查看:428
本文介绍了C#richtextbox查找和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的输入和期待输出



输入
$ 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 the String.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屋!

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