Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I have a list view in which I am continuously updating feeds through a String variable.

I wanted to provide the user facility to open the links directly coming in the messages. e.g.

$ASX Message : xxxXXXxx...1234.. www.yahoo.com

$ASX Message : xxxXXXxx...1234.. www.google.com

$ASX Message : xxxXXXxx...1234.. www.msn.com

I want the message to be displayed like above example and needed to be directed to open the relevent page in iexplorer when clicked.

Since I am getting these as string messages I am unable to display them as link.

Please help

Regards,

Ashish
Posted
Updated 7-Oct-10 21:42pm
v2
Comments
Dalek Dave 8-Oct-10 3:42am    
Edited for Grammar

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.
 
Share this answer
 
v3
Comments
Toli Cuturicu 8-Oct-10 15:01pm    
Wow!
< a href ="your url address">your text</a>

mat be it will solve
 
Share this answer
 
Comments
honeyashu 8-Oct-10 1:43am    
No.. this will simply display as String.. Its not ASP buddy... :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900