.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Regular Expressions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Find number from a string

Posted By:Deepika Haridas       Posted Date: August 30, 2009    Points: 10    Category: Regular Expressions    URL: http://www.dotnetspark.com  
 

Find number from a string using regular expression.

This regular expression will display if a string entered contains a number.


private void btnFindNumber_Click(object sender, System.EventArgs e)
{

Regex re = new Regex(@"\d+");
Match m = re.Match(txtFindNumber.Text);
if (m.Success)
{
lblResults.Text = string.Format("RegEx found " + m.Value + " at position " + m.Index.ToString());
}
else
{
lblResults.Text = "You didn't enter a string containing a number!";
}
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend