In my ASP.NET application, I want to use regular expressions to change URLs into hyper links in user posts, for example:
http://www.somesite.com/default.aspx
to
<a href="http://www.somesite.com/default.aspx">http://www.somesite.com/default.aspx</a>
This is fairly easy using Regex.Replace(), but the problem I'm having is that I want to truncate the link text if the URL is too long, for example:
http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8ed232c23de7f9121d&n=93b34a732e074c934e32d123de19c83d
to
<a href="http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8ed232c23de7f9121d&n=93b34a732e074c934e32d123de19c83d">http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8...</a>
so that it displays like this:
http://www.somesite.com/files/default.aspx?id=a78b38ae723b1f8...
I tried to use Regex.Matches() but I don't know how to replace the text, any suggestions?
Thanks for your help ...
Edit:
Never mind guys, I figured it out on my own, it turned out to be incredibly simple, I just used a MatchEvaluator!
public static string Replace(
string input,
string pattern,
MatchEvaluator evaluator
)