by Sai gowtham

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

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course