我只需在winform应用程序中选择RichTextBox中的粗体文本,然后将其括在括号中:例如:The RichTextBox element describes the desired action that should be applied to the cluster activity that defines the Rollup Rule.。
粗体案文将变成:
[Rollup Action] [Rollup Rule].谢谢。
发布于 2011-07-05 08:29:30
一种解决方案是使用Regex查找粗体文本,并将其替换为相同的内容,但添加了方括号:
richTextBox.Rtf = Regex.Replace(richTextBox.Rtf, @"\\b ((\w| )*)", RegExSample.AddBrackets);MatchEvaluator:
public class RegExSample
{
public static string AddBrackets(Match match)
{
return String.Format("[{0}]", match.Value);
}
}您的样本的输出将是:
汇总操作元素描述了应该应用于定义汇总规则的集群活动所需的操作
您还可以更新regex,以确保它在所有情况下都正常工作。
https://stackoverflow.com/questions/6578997
复制相似问题