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,


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,


c# code to Count number of 1's in a given range of integer (0 to n)

0 Answers  


How to pass multiple rows from one gridview to another gridview after clicking the checkbox.

1 Answers   Satyam,


How to Create a Treeview Menu in ASP.NET with C#?

1 Answers  






How to Create Files by Using the FileInfo Class?

1 Answers  


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

2 Answers   Sify,


Write a function which accepts list of nouns as input parameter and return the same list in the plural form. Conditions: i) if last letter is r then append s ii) if word ends with y then replace it by ies iii) call this function in main() and produce the required output. for eg:- if chair is input it should give chairs as output.

0 Answers   Mind Tree,


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

1 Answers  


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

4 Answers   Wipro,


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

8 Answers   Black Pepper, Infosys, Mind Tree,


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  


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)