-2

我想从文件中读取一些特定信息并在表单应用程序中.txt显示特定行。文件模板如下所示 :TextBox.txt

info1:这里有一些字符...

info2:这里有一些字符...

info3:一些字符

   Col1  Col2  Col3  Col4  Col5   Col6   Col7   Col8   Col9  
  <h1> ---------------------------------------------------------------  

   001   a      b     c    d      e       f       g      h  
   001   c      a     f    d      f       b       e      t  
   001   a      b     c    d      e       f       g      h  

   002   c      a     f    b      f       b       e      t  
   002   z      e     f    d      f       b       e      m          
   002   c      a     j    u      t       b       h      t  
   002   y      l     f    d      f       b       n      t  

   006   c      a     j    y      t       b       d      t   

   007   b      a     f    d      r       b       t      t  
   007   c      a     f    r      f       b       e      q  
   007   c      a     f    d      f       x       z      t  
   007   c      p     f    d      s       b       a      t  
   007   c      a     f    h      f       b       e      p  

   <h1>----------------------------------------------------------------  

附加信息:类似于 info3 的行数不固定;

我需要的功能是在 a 中插入TextBox与第一列相对应的一组数字(例如 001),然后在另一个文本框中显示文件的标题信息,列标题,然后,仅以引入的数字开头的行不包括其他行。一个好的解决方案应该是什么?
谢谢。

4

1 回答 1

2

在这种情况下,您应该使用 String.StartsWith

例子:

using (var reader = new System.IO.StreamReader(@"C:\file.txt"))
{
    while (!reader.EndOfStream)
    {
        var line = reader.ReadLine();

        if (line.StartsWith("info"))
        {
            // do something
        }
    }

    reader.Close();
}
于 2011-09-07T11:40:53.377 回答