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

Can you declare an array of mixed Types?

1 Answers   HCL,


How to Create Files by Using the FileInfo Class?

1 Answers  


how to change password in .net with c # with ado.net and also SQL server 2008 change password

1 Answers  


IS Array list is generic or non generic

1 Answers  


. Write a program to print the following outputs using for loops $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

3 Answers  


Write a program. there are 1..n numbers placed in an array in random fashion with one integer missing. find the missing number.

1 Answers   Infosys, Mind Tree,


program for straight line(y=mx+c)

0 Answers   Mind Tree,


Write a program to convert postfix expression to infix expression.

0 Answers   Mind Tree,


program for string reverse(eg:- i am boy -> boy am i)

8 Answers   Black Pepper, Infosys, Mind Tree,


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

1 Answers  


How to export 2 datatables of a single dataset to 2 different worksheets of a single MSExcel file ?

0 Answers   Eastcom Systems,


Write a program to input an integer and - display the reverse - display the sum of each digit - should include logic that considers the input number as any number of digits long

2 Answers   Mind Tree,


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)