1.C#操作TXT文本的源码源代码!
C#操作TXT文本的源码c 范例宝典 源码源代码!
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;
using System.IO;
namespace OutputText
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender,源码群排名软件源码 EventArgs e)
{
this.btnShow.Click += new EventHandler(btnShow_Click);
}
void btnShow_Click(object sender, EventArgs e)
{
// 判断输入的行数
string input = this.txtInput.Text.Trim();
//用于读文本的时候记数
int numOfTextFile;
// int.TryParse验证输入的是不是行数
if (int.TryParse(input, out numOfTextFile))
{
//StreamReader 打开文件
using(StreamReader sr = new StreamReader(@"D:\text.txt"))
{
int count=0;
// ReadLine 读一行
string txtContent = sr.ReadLine();
while (txtContent != null)
{
//读一行记一下数
count++;
//如果和你要求的输入行数匹配,显示文本,源码asp微信源码中断循环
源码电商溯源码if (count == numOfTextFile)
源码电商溯源码{
源码电商溯源码this.textBox1.Text = txtContent;
源码电商溯源码this.textBox2.Text = txtContent;
源码电商溯源码this.textBox3.Text = sr.ReadLine();
源码电商溯源码break;
源码电商溯源码}
源码电商溯源码else
源码电商溯源码{
源码电商溯源码txtContent = sr.ReadLine();
源码电商溯源码}
源码电商溯源码}
源码电商溯源码}
源码电商溯源码}
源码电商溯源码}
源码电商溯源码}
源码电商溯源码}
源码电商溯源码