gpt4 book ai didi

c# - 选择粗体文本

转载 作者:太空宇宙 更新时间:2023-11-03 14:15:57 24 4
gpt4 key购买 nike

我只需要在 winform 应用程序的 RichTextBox 中选择粗体文本,然后将其括在方括号中:例如:The <strong>Rollup Action</strong> element describes the desired action that should be applied to the cluster activity that defines the <strong>Rollup Rule</strong> .
粗体文本将变为:<br/>[<strong>Rollup Action</strong>] [<strong>Rollup Rule</strong>] .谢谢。

最佳答案

一种解决方案是使用 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);
}
}

您的样本的输出将是:

The [Rollup Action] element describes the desired action that should be applied to the cluster activity that defines the [Rollup Rule]

您还可以更新正则表达式以确保它在所有情况下都能正常工作。

关于c# - 选择粗体文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6578997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com