How to Extract number from a string using C# ?

Published on March 27, 2013 by abundantcode

Filed under C#

Last modified March 27, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 3 (2 votes)

This article have been viewed 8669 times

Regular expression lets you to do some of the tasks quickly in C# and now such of the task that can be done using the Regex class is to extract number from a string using C# .

How to Extract number from a string using C# ?

Below is a sample sourecode that demonstrates how to extract number from a string using C#.

string inputData = "Abundantcode.com-023";

var data = Regex.Match(inputData, @"\d+").Value;

MessageBox.Show(data);

The Regex.Match uses the System.Text.RegularExpressions name.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

1 Comment

  1. Peter

    Hello!
    Firstly I would like to say big thank you and congratulate for this simple, however very useful tutorials. Secondly I would like to know how to extract numbers of certain position and scale, for example numeric (a,b); a>=4, b=2?
    Greetings!
    Peter

    September 19, 2014 - 11:51 am – Reply

Leave a Comment


x

You might be Interested in these Posts

C# and Lambda - Finding all the elements of an integer array less than 35

Here's a sample code snippet demonstrating how to find all the elements of an integer array that is ...

C# and LINQ - Finding all the elements of an integer array less than 35

Here's a sample code snippet demonstrating how to find all the elements of an integer array that is ...

How to get the CommandLine of the Current Application in C# ?

You might need to get the information that contains the commandline which is used to execute the cur...