Simply assume that the
string
you have is
string str = "I would always love to open www.codeproject.com for my KB updating and I always prefer www.google.com as my search engine";
So for replacement regex pattern will be
Regex regex = new Regex(@"\bwww.[A-Za-z-0-9]+\.com\b");
Now replace the
Regex
matched string with the
Anchor
,
Here you go,
str = regex.Replace(str,new MatchEvaluator(urlString));
Make
MatchEvaluator
delegate
for replacement
public static urlString(Match m)
{
return String.Format("<a href='http://{0}">{0}</a>",m.ToString());
}
Now you will have your final string in str Variable
Just do
Response.Write(str)
Your output will be,
I would always love to open
www.codeproject.com for my KB updating and I always prefer
www.google.com as my search engine
See the Magic.
Please
vote and
Accept Answer if it Helped.