判断字符串中的数字(可以进行演变)

  static void Main(string[] args)
        {
            Console.WriteLine("请输入一个字符串:");
           string str= Console.ReadLine();
           Console.WriteLine("
");
           for (int i = 0; i < str.Length; i++)
           {             
               string n=  str.Substring(i, 1);
               bool b =Number.GetNumber(n);
               if (b ==true)
               {
                   //Console.WriteLine(n+",");
                   Console.Write(n+",");
               }
           }         
               Console.ReadKey();
        }
    }
  public   class Number
    {
        public static bool GetNumber(string str)
        {
            bool b = false;
            string[] arryList = { "0","1","2","3","4","5","6","7","8","9"};
            foreach (string item in arryList)
            {
                if (item == str)
                {
                    b = true;
                    break;
                }               
            }
            return b;  
        }
    }
View Code
原文地址:https://www.cnblogs.com/haimingkaifa/p/5894065.html