StreamReader sr = new StreamReader(文件路径, System.Text.Encoding.Default);while (sr.Peek() >= 0)
{
    str = sr.ReadLine();
    //这里自己想办法处理吧
}

解决方案 »

  1.   

    參考:// Create a new file.
    using (FileStream fs = new FileStream("test.txt", FileMode.Create))
    {
    // Create a writer and specify the encoding.
    // The default (UTF-8) supports special Unicode characters,
    // but encodes all standard characters in the same way as
    // ASCII encoding.
    using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
    {
    // Write a decimal, string, and char.
    w.WriteLine(124.23M);
    w.WriteLine("Test string");
    w.WriteLine('!');
    }
    }
    Console.WriteLine("Press Enter to read the information.");
    Console.ReadLine();
    // Open the file in read-only mode.
    using (FileStream fs = new FileStream("test.txt", FileMode.Open))
    {
    using (StreamReader r = new StreamReader(fs, Encoding.UTF8))
    {
    // Read the data and convert it to the appropriate data type.
    Console.WriteLine(Decimal.Parse(r.ReadLine()));
    Console.WriteLine(r.ReadLine());
    Console.WriteLine(Char.Parse(r.ReadLine()));
    }
    }
      

  2.   


                System.IO.StreamReader sr = new System.IO.StreamReader(FilePath, System.Text.Encoding.Default);            while (sr.Peek() >= 0)
                {
                    string str = sr.ReadLine();                Console.WriteLine(str);                if (str.Contains("─"))
                        continue;                string[] ss = str.Split('|');
                    List<string> datalist = new List<string>();
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if (ss[i].Trim().Length == 0)
                            continue;                    datalist.Add(ss[i]);
                    }                foreach (string s in datalist)
                        Console.WriteLine(s);                if (datalist.Count == 1)
                        dgvResult.Rows[dgvResult.Rows.Count - 1].Cells[1].Value += datalist[0];                if (datalist.Count == 2)
                        dgvResult.Rows.Add(datalist[0], datalist[1]);                if (datalist.Count == 4)
                    {
                        dgvResult.Rows.Add(datalist[0], datalist[1]);
                        dgvResult.Rows.Add(datalist[2], datalist[3]);
                    }
    如果需要源程序,就发邮件给我吧,[email protected]
      

  3.   

    这是谁写进txt?读就要谁去写读代码.哈哈
      

  4.   


    string tempString = string.Empty;
    string All = string.Empty;
    using (StreamReader sr = new StreamReader(filepath,System.Text.Encoding.Default))
                {
                    while (sr.Peek() >= 0)
                    {
                        All = tempString = sr.ReadLine();
                        if (tempString == "【基本资料】")
                        {
                            for (int i = 0; i < 50; i++)
                            {
                                tempString += sr.ReadLine().ToString();                            
                            }                        
                           
                            this.txtResult.Text = Encode(tempString);
                        }
                        if (tempString == "【股本历次变更状况】")
                        {
                            for (int j = 0; j < 6; j++)
                            {
                                All += sr.ReadLine().ToString();                           
                            }
                            
                            this.txtResult.Text +=  Encode(All);
                        }                    
                    }
                }
     public string Encode(string str)
            {
                if (str.Length > 0)
                {
                    str = str.Replace("|", "");
                    str = str.Replace("─", "");
                    str = str.Replace("┤", "");
                    str = str.Replace("├", "");
                    str = str.Replace("┼", "");
                    str = str.Replace("┴", "");
                    str = str.Replace("└", "");
                    str = str.Replace("┬", "");
                    str = str.Replace("┌", "");
                    str = str.Replace("┐", "");
                    return str;
                }
                else
                {
                    return str;
                }
            }  
      

  5.   

    把读取结果用string[] stra=读取结果.split('\n')
    先用回车行分隔开,放在一个数组然后循环输出stra[i]里面的数据,然后再把stra[i]里面的数据通过substring 或split提取出来因为没有规律,只能自己慢慢分析
      

  6.   

    要是网页的话写个爬虫抓取一下还是简单的,winform的不会
      

  7.   

    给你一点提示,注意代码的可扩展性,一旦你的txt文件的格式变了,你的代码就要变化。所以你利用正则表达式会更好一点,对全文进行匹配要简单得多
      

  8.   

    多说无益StreamReader就搞定了,至于你的文本格式,先把垃圾符号在读取IO流的时候剔除,开一个比较大的缓冲区存储,如果格式固定,直接按缓冲区的位置取数据就可以了