by @codeexamples

Extracting number from a string in C#

Home » c-sharp » Extracting number from a string in C#

This below example, shows you how to extract the number from a string in c# by use of linq.

using System;
using System.Linq;

class GetNum{
  static void Main() {
   string test = "123hello456";
   string numericPhone = new String(test.Where(Char.IsDigit).ToArray());   System.Console.WriteLine(numericPhone);
  }
}

Output:

123456