0

古いデータベースからのテキストがあります。テキストは次のようにフォーマットされます。

これはテキストの最初の部分です #これは太字でフォーマットする必要があります# これは通常のテキストである必要があります #これは再び太字でフォーマットする必要があります# など。

上記のように、# 記号の内側にあるすべてのグループを見つけて、それらの周りに<b></b>or<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 に答える