2012-11-15 31 views
0

我有一些舊數據庫中的文本。文本的格式是這樣的:.NET正則表達式用標籤替換轉義字符

這是文本#此的第一部分應以粗體# 格式化,這應該是正常的文本,然後#這應該大膽 再次#等進行格式化。

正如你可以在上面看到,我需要找出所有#跡象內的組,並設置<b></b><strong></strong>標籤身邊。我怎樣才能在C#中做到這一點?

回答

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>"); 
+1

太棒了!謝謝。 – Gunnar