首页 > 技术文章 > c#语言-Split拆分

koker 2016-04-23 20:22 原文



static void Main(string[] args) { int[,] cj = new int[3,4]; Console.WriteLine("学号\t语文\t数学\t外语"); for (int i = 0; i < 3; i++) { Console.Write(i + 1); Console.Write("\t"); string s = Console.ReadLine(); string[] str = s.Split(' ','\t',',');/////Split(' ','',''......)或Split(','),Split('\t')等等很多种都可以达到同样的目的。
目的就是将字符串拆分成n串;
int yw = Convert.ToInt32(str[0]); int sx = Convert.ToInt32(str[1]); int wy = Convert.ToInt32(str[2]); Console.WriteLine(yw + sx + wy); } // string s = Console.ReadLine(); //int yw, sx, wy; //string[] str = s.Split(' ',',','-','\t'); //yw = Convert.ToInt32(str[0]); //sx = Convert.ToInt32(str[1]); //wy = Convert.ToInt32(str[2]); //Console.WriteLine("语文:{0},数学:{1},外语:{2}", yw, sx, wy); }

 

推荐阅读