0

我有一些来自旧数据库的文本。文本格式如下:

这是文本的第一部分#this 应该用粗体格式化#这应该是普通文本然后#this 应该再次用粗体格式化#等等。

正如您在上面看到的,我需要找到 # 符号内的所有组,并在它们周围设置一个<b></b><strong></strong>标记。我怎样才能在 C# 中做到这一点?

4

1 回答 1

2
string input = @"This is the first part of the text #this should be formatted in bold# this should be normal text and then #this should be formatted in bold again# and so on.";
var output = Regex.Replace(input, @"#(.+?)#", "<b>$1</b>");
于 2012-11-15T21:25:43.397 回答