如何使用匹配整个单词替换richTextBox中字符串的所有实例? [英] How to replace all instances of a string inside a richTextBox using match whole word?

查看:94
本文介绍了如何使用匹配整个单词替换richTextBox中字符串的所有实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我想做的是仅在字符串与比较字符串完全匹配的情况下,才在richtextbox中搜索rtf文本并替换字符串的所有实例.
我尝试使用RTB.Replace方法,并且还定义了一个StringComparison对象,以帮助比较彼此跳转时的字符串.但是,例如,如果我有文本"aa aaaca",而我正在搜索要替换为bbb的aa,那么我将拥有类似"bbb bbbaca"的内容,而不仅仅是"bbb aaaca"
有帮助吗?

Hey guys, what i want to do is search a rtf text inside a richtextbox and replace all instances of a string, only if the string exactly matches the comparison string.
I tried using the RTB.Replace method and I also defined a StringComparison object to help compare the strings when jumping from one another. But if for example I have the text "aa aaaca" and i''m searching for aa to replace with bbb then i''ll have something like "bbb bbbaca", instead of just "bbb aaaca"
Any help?

推荐答案

尝试使用Regex类来做到这一点.(System.Text.RegularExpression.Regex)..
这是链接..

http://tim.oreilly.com/pub/a/oreilly/windows/news/csharp_0101.html

阅读如何在简单匹配"之后替换替换字符串"中的字符串
try to do that with Regex class.(System.Text.RegularExpression.Regex)..
this is the link..

http://tim.oreilly.com/pub/a/oreilly/windows/news/csharp_0101.html

read how to replace the string in "Replacing Strings" just after the "Simple Matches"


这篇关于如何使用匹配整个单词替换richTextBox中字符串的所有实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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