2011-07-07 28 views
1

我工作的一個留言板,我想有以下回復/報價系統:解析回覆/報價,並使其成爲一個超級鏈接ASP.NET

@5432 //post number 
This is a reply to a post 
@5647 
This is a reply to another post 

這是純文本,服務器 - 邊我想更換它,所以它結束這樣的:

<a href="#5432>@5432</a> 
... 

我覺得正則表達式是^@\d+,但我不知道如何實現它,尤其是與多個ocurrences。

This ASP.NET + C#,btw。

回答

0

這裏是你如何在C#中做到這一點:

string str = @"@5432 //post number 
      This is a reply to a post 
      @5647 
      This is a reply to another post"; 

Regex.Replace(str, @"(@)(\d+)", @"<a href=""#$2"">$1$2</a>") 
+0

完美的作品,謝謝! –