您的位置:首页 > 编程语言 > C#

C# 面向对象,字符串中取数组

2016-04-01 17:16 357 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string s;
string result;
int sum;
s = Console.ReadLine();
sum = Myclass.getnumber(s, out result);
Console.WriteLine("一共有"+ sum +"个数字,"+"所有的数字是"+ result);
Console.ReadKey();
}
}

class Myclass
{
public static int getnumber(string strsource, out string result)
{
char []s= strsource.ToCharArray();
char[] s1 = new char[1];
result="";
int i = 0;
foreach (char item in s)
{
if (item >= 48 && item <= 57)
{
s1[0] = item;
result += s1[0].ToString();
i++;
}
}
return i;
}
}

}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: