using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _7练习6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string s = tb_content.Text; //string[] str = s.Split('\r\n');方法1: 按钮\r\n进行split //MessageBox.Show("s=="+s); //string[] str = s.Split(new string("\r\n",) //string[] lines = tb_content.Lines; //取得所有列 //记住Split分割多个字符的用户法啊啊啊啊啊啊 string[] lines = s.Split(new string[]{"\r\n"},StringSplitOptions.RemoveEmptyEntries); string maxName = ""; int maxScore = -1; foreach (string line in lines) { string[] strs = line.Split('='); string name = strs[0]; string strScore = strs[1]; int score = Convert.ToInt32(strScore); if (score > maxScore) { maxName = name; maxScore = score; } } MessageBox.Show(string.Format("第一名是:{0},成绩:{1}", maxName, maxScore)); } } }