Automatically Hyperlink URLs and E-Mail Addresses in
ASP.NET Pages with C#



Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#..

Answer / guest

using System.Text.RegularExpressions;
The second step is to detect a URL:

Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",
RegexOptions.IgnoreCase|RegexOptions.Compiled);

Here is how to detect an e-mail address:

Regex emailregex = new
Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)",
RegexOptions.IgnoreCase|RegexOptions.Compiled);



private void Button1_Click(object sender, System.EventArgs
e)
{
string strContent = InputTextBox.Text;
Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",
RegexOptions.IgnoreCase|
RegexOptions.Compiled);
strContent = urlregex.Replace(strContent,
"");
Regex emailregex = new
Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)",
RegexOptions.IgnoreCase| RegexOptions.Compiled);
strContent = emailregex.Replace(strContent, "");
lbContent.Text += ""+strContent;
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Sharp Code Interview Questions

write a Program to copy the string using switch case.

0 Answers   Mind Tree, Wipro,


program for straight line(y=mx+c)

0 Answers   Mind Tree,


Coding for Manipulate XML File Data Using C#?

1 Answers  


Event Handling in C# Triggering a Button

1 Answers  


c# coding for a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors not using the Big-integer and Exponential Function's.

1 Answers   TCS,


how can i split sting in textbox in windows application using c# .net

2 Answers  


How to find No of classes,Packages,No of Methods per Classes and Depth of Inheritance for selecting source code in windows form application using c# .net? (Source code is input Program. It may be Java or .net) Please help me..) Thanks..)

0 Answers  


how to get the table names via c sharp and column names also?

2 Answers   Sify,


Code for Searching for Multiple Matches with the MatchCollection Class?

0 Answers   TCS,


How to use ASP.NET 2.0's TreeView to Display Hierarchical Data?

1 Answers  


program to reverse the order of digits in a given number of any length.

1 Answers   Mind Tree,


how do i copy textbox contents of 1 form to another form

4 Answers   Wipro,


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)