How to Extract number from a string using C# ?

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#.

using System;
using System.Text.RegularExpressions;
public class Hello {
    public static void Main() {
        string inputData = "Abundantcode.com-023";
        var data = Regex.Match(inputData, @"\d+").Value;
        Console.WriteLine(data);
    }
}

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

1 Comment

  • 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

Leave Your Comment