Friday 11 January 2013

Extract all Number from String


Extract all Number from String


There are some time when we need to get the numbers present in a particular string.. The following example will help you to achieve the same.. 

Have a look at the code-snippet below:


private string ExtractNumbers(string Expression)

{

string result = null;

char Letter;

for (int i = 0; i < Expression.Length; i++)

{

Letter = Convert.ToChar(Expression.Substring(i, 1));

if (Char.IsNumber(Letter))

{

result += Letter.ToString();

}

}

lblNum.Text=result;

}  

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top