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

c#语言-Split拆分

2016-04-23 20:22 501 查看
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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: