111,121
社区成员
发帖
与我相关
我的任务
分享
string ID = textBox1.Text;
string path = @"../members.txt";
StreamReader sr = new StreamReader( path );
string[] content = new string[0];
bool find = false;
string str = string.Empty;
while ( !sr.EndOfStream )
{
str = sr.ReadLine();
content = str.Split( ' ' );
if ( content[1].Equals( ID ) )
{
find = true;
textBox2.Text = content[0];
textBox3.Text = content[1];
textBox4.Text = content[2];
break;
}
}
sr.Close();
if ( !find )
{
MessageBox.Show( "查无此人" );
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication4
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string ID = textBox1.Text;
string path = @"../members.txt";
StreamReader sr = new StreamReader(path);
string[] content = new string[0];
int row = 0;
while (!sr.EndOfStream)
{
row++;
}
for (int i = 0; i < row; i++)
{
content[i] = sr.ReadLine();
string[] temp = content[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < temp.Length; j++)
{
if (temp[j] == ID)
{
textBox2.Text =temp[0];
textBox3.Text =temp[1];
textBox4.Text =temp[2];
}
else
continue;
}
}
MessageBox.Show("查无此人");
}
}
}