ITPub博客

首页 > Linux操作系统 > Linux操作系统 > C#获取文本文件某行数据

C#获取文本文件某行数据

原创 Linux操作系统 作者:fangqm 时间:2010-11-11 10:07:49 0 删除 编辑
 private void Form1_Load(object sender, EventArgs e)
        {
            int j=0;
          label1.Text=  FileRowText(@"c:\update.dat",2, ref j);
        }

        #region 获取文本某行数据
        ///
        /// 获取文本文件某行数据
        ///

        /// 文本文件路径
        /// 第几行
        /// 返回总行数
        ///
        private string FileRowText(string filePath,int i, ref int j)
        {
          
            StreamReader sr = File.OpenText(filePath);
            string str = "";
            string text = "";
            int num = 0;
            while ((str = sr.ReadLine()) != null)
            {
                num++;
                if (num == i)
                {
                    text = str;
                }
            }
            j = num;
            sr.Close();
            return text;
        }
        #endregion

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23109131/viewspace-677923/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 动态配置WCF
请登录后发表评论 登录
全部评论
创业项目 https://u.rscode.cn

注册时间:2010-03-24

  • 博文量
    297
  • 访问量
    784646