Format URLs in string to HTML Links in C#


/ Published in: C#
Save to your folder(s)

Will return a string that has any matched URLs wrapped in `<a>` tags.

Example: `"This is a link to http://foobar.com . Please visit !"`

Becomes: `"This is a link to <a href='http://foobar.com'>http://foobar.com</a> . Please visit!"`

Note: Opens links in new window.

Credit for regex:
[Faraz Shah Khan](http://weblogs.asp.net/farazshahkhan/archive/2008/08/09/regex-to-find-url-within-text-and-make-them-as-link.aspx "Credit")

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.