zoukankan      html  css  js  c++  java
  • C#读取txt文件返回DATATABLE

    //1.打开资源管理器

    OpenFileDialog open = new OpenFileDialog();

      if (open.ShowDialog() == DialogResult.OK)            

    {              

       textBox1.Text =open.FileName;       

     }

    //传入txt文件路径参数 读取txt文件所有内容 返回DATATABLE

     public DataTable GetTxt(string pths)
            {
                StreamReader sr = new StreamReader(pths, Encoding.GetEncoding("GB2312"));
                string txt = sr.ReadToEnd().Replace(" ", "-");
                string[] nodes = txt.Split('-');
                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(string));
                foreach (string node in nodes)
                {
                    string[] strs = node.Split('-');
                    DataRow dr = dt.NewRow();
                    dr["ID"] = strs[0];
                    dt.Rows.Add(dr);
                }
                return dt;
            }

  • 相关阅读:
    Jmeter的两种录制脚本的方式
    【.NET】设置EntityFramework中decimal类型数据精度 [转]
    vscode格式化vue不换行
    mysql5.7 noinstall 安装 【转载】
    配置STP、RSTP以及负载均衡
    配置3层交换机VLAN间通信
    配置单臂路由
    配置DTP
    配置trunk
    配置VLAN
  • 原文地址:https://www.cnblogs.com/-lxl/p/5856525.html
Copyright © 2011-2022 走看看