/* 从一段文本中提取所有的数字。*/
static void Main(string[] args)
{
Console.WriteLine("请输入一段文字");
string input = Console.ReadLine();//输出文字
char[] ch = input.ToCharArray();//将字符串复制到新的数组中
int result = -1;//定义初始值
for (int i = 0; i < input.Length;i++ )//遍历循环
{
switch (ch[i])//可能出现的情况
{
case'0':
result = 0;
break;
case'1':
result = 1;
break;
case '2':
result = 2;
break;
case '3':
result = 3;
break;
case '4':
result = 4;
break;
case '5':
result = 5;
break;
case '6':
result = 6;
break;
case '7':
result = 7;
break;
case '8':
result = 8;
break;
case '9':
result = 9;
break;
default:
continue;
}
if (result != -1)//结果判断输出
{
Console.Write(ch[i]);
}
}
Console.ReadKey(); |