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; } } }
运行结果:
相关文章推荐
- C# 统计字符串数字个数并输出
- C#第四次上机
- 2016-4-1--C#委托delegate
- c#类的初使用
- C#--冒泡排序
- C#第四章3.(1)
- C# 上机题 写一个静态方法,输出字符串中大小写字母、数字和其他字符个数
- c#-输出参数
- C#学习(9):通过反射设置泛型类型的属性及值
- C#大文件读取和查询--内存映射
- C#中axWindowsMediaPlayer控件的用法
- C#中,switch case语句中多个值匹配一个代码块的写法
- C# 清空sessin
- C# Dictionary用法总结
- C# ——输入 若干字符组成的字符串,写静态方法,统计并输出各种字符的数目
- C#装箱与拆箱
- c# 最简单的线程
- C#基本语法学习(十)
- C# this 关键字
- c#中委托与多线程的实质