Quick and simple way to parse numbers in string

10:36 AM

Some times we have to pull numbers from mixed string. There are several ways to do it, so here i will indroduce some easy and quick one :)

string fullSentence ="Just a sentence with numbers from 1 asd f3 234 6to10111"
string numbers = Regex.Split(fullSentetnce @"\D+"); 

foreach(string number in numbers)
{
  if(!string.IsNullOrEmpty(number)
  {
    int i =int.Parse(number);
    Console.WriteLine("{0}",i); 
  }
}

Result:



You Might Also Like

0 comments.

Popular Posts

Google+ Followers

Total Pageviews