extract all numeric values from a string using Linq
Have you ever wanted to get all the numeric values from a string?
One simple way is to iterate over the string and evaluate each character but it require few lines of code so why not Linq !?
The following code extract all numeric values:
string str = "a12/343="; int number = Convert.ToInt32(new string(str.Where(c => Char.IsDigit(c)).ToArray()));
the output will be: 12343
remember to import Linq reference:
using System.Linq;
1 Response
tnx for info!