
从一个记录了学生成绩的文本文档,每个学生成绩是一行,每 行是用|分割的数据,用|分割的域分别是姓名、年
从一个记录了学生成绩的文本文档,每个学生成绩是一行,每行是用|分割的数据,用|分割的域分别是姓名、年龄、成绩,写程序取出成绩最高学生的姓名和成绩。string[]line...
从一个记录了学生成绩的文本文档,每个学生成绩是一行,每行是用|分割的数据,用|分割的域分别是姓名、年龄、成绩,写程序取出成绩最高学生的姓名和成绩。
string[] lines = System.IO.File.ReadAllLines(@"E:\C#study\ConsoleApplication1\字符串\1.txt", Encoding.Default);
foreach (string item in lines)
{
string[] strs = item.Split(new string[] {"|"},StringSplitOptions.RemoveEmptyEntries);
foreach(string item1 in strs)
Console.WriteLine(item1);
}
C#怎么写,我写到上面哪就不会了,也不知道自己写的对不对,我是个初学者,学到split函数遇到的题,请用split写出来! 展开
string[] lines = System.IO.File.ReadAllLines(@"E:\C#study\ConsoleApplication1\字符串\1.txt", Encoding.Default);
foreach (string item in lines)
{
string[] strs = item.Split(new string[] {"|"},StringSplitOptions.RemoveEmptyEntries);
foreach(string item1 in strs)
Console.WriteLine(item1);
}
C#怎么写,我写到上面哪就不会了,也不知道自己写的对不对,我是个初学者,学到split函数遇到的题,请用split写出来! 展开
2个回答
展开全部
string[] studentsInfo = System.IO.File.ReadAllLines(@"E:\C#study\ConsoleApplication1\字符串\1.txt", Encoding.Default);
if (studentsInfo.Length > 0)//如果有成绩数据
{
System.Collections.Generic.SortedList<Int32, string> students = new System.Collections.Generic.SortedList<Int32, string>();
foreach (string student in studentsInfo)
{
string[] studentLine = student.Split('|');
students.Add(Convert.ToInt32(studentLine[2]), studentLine[0]);
}
Console.WriteLine("成绩最高的学生信息为:");
Console.Write("姓名:");
Console.WriteLine(students.Values[students.Count - 1]);
Console.Write("成绩:");
Console.Write(students.Keys[students.Count - 1]);
}
Console.ReadKey();
if (studentsInfo.Length > 0)//如果有成绩数据
{
System.Collections.Generic.SortedList<Int32, string> students = new System.Collections.Generic.SortedList<Int32, string>();
foreach (string student in studentsInfo)
{
string[] studentLine = student.Split('|');
students.Add(Convert.ToInt32(studentLine[2]), studentLine[0]);
}
Console.WriteLine("成绩最高的学生信息为:");
Console.Write("姓名:");
Console.WriteLine(students.Values[students.Count - 1]);
Console.Write("成绩:");
Console.Write(students.Keys[students.Count - 1]);
}
Console.ReadKey();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询