Friday, 21 June 2013

Get Number from string



      
Get Number included in string with alphnumerical characters and special characters
 for ex.     AH23K4!%7     will returns as  2347

Here is code for same : 

       private string Number(string str)
        {
            string Num = string.Empty;
            for (int i = 0; i < str.Length; i++)
            {
                int j;
                if (int.TryParse(str[i].ToString(), out j))
                {
                    Num += j.ToString();
                }
            }
            return Num;
        }

No comments:

Post a comment