code_junkie

Regular expression to convert urls to hyperlinks in .Net

Nov 13th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. http://www.somesite.com/default.aspx
  2.  
  3. <a href="http://www.somesite.com/default.aspx">http://www.somesite.com/default.aspx</a>
  4.  
  5. http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8ed232c23de7f9121d&n=93b34a732e074c934e32d123de19c83d
  6.  
  7. <a href="http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8ed232c23de7f9121d&n=93b34a732e074c934e32d123de19c83d">http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8...</a>
  8.  
  9. http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8...
  10.  
  11. public static string Replace(
  12. string input,
  13. string pattern,
  14. MatchEvaluator evaluator
  15. )
  16.  
  17. string displayText = url.Substring(0, maxLength);
  18. string hyperlink = string.Format("<a href="{0}">{1}</a>", url, displayText);
Add Comment
Please, Sign In to add comment