0

我有一个文本文件,其中包含如下文本:

#rn=three            rutid=svt#
#outgoing#
  sz          sucs        sw-loss     ans-comp    cong        dur-absy    
  0000000000  0000000000  0000000000  0000000000  0000000000  0000000000
  dsz         ratpt       ovfl        usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00008.00    00000.00    00008.00    00000.00    00000.00    00000.00  
#incoming#
  sz          sucs        ans-comp    usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00008.00    00000.00    00008.00    00000.00    00000.00    00000.00  

#rn=board            rutid=svt#
#outgoing#
  sz          sucs        sw-loss     ans-comp    cong        dur-absy    
  0000000000  0000000000  0000000000  0000000000  0000000000  0000000000
  dsz         ratpt       ovfl        usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  
#incoming#
  sz          sucs        ans-comp    usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  

#rn=conf6            rutid=svt#
#outgoing#
  sz          sucs        sw-loss     ans-comp    cong        dur-absy    
  0000000000  0000000000  0000000000  0000000000  0000000000  0000000000
  dsz         ratpt       ovfl        usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  
#incoming#
  sz          sucs        ans-comp    usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  

#rn=dtimon           rutid=svt#
#outgoing#
  sz          sucs        sw-loss     ans-comp    cong        dur-absy    
  0000000000  0000000000  0000000000  0000000000  0000000000  0000000000
  dsz         ratpt       ovfl        usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  
#incoming#
  sz          sucs        ans-comp    usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  

#rn=conf10           rutid=svt#
#outgoing#
  sz          sucs        sw-loss     ans-comp    cong        dur-absy    
  0000000000  0000000000  0000000000  0000000000  0000000000  0000000000
  dsz         ratpt       ovfl        usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  
#incoming#
  sz          sucs        ans-comp    usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  

#rn=rconf6           rutid=svt#
#outgoing#
  sz          sucs        sw-loss     ans-comp    cong        dur-absy    
  0000000000  0000000000  0000000000  0000000000  0000000000  0000000000
  dsz         ratpt       ovfl        usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  
#incoming#
  sz          sucs        ans-comp    usg-bsy     usg-ovall   usg-ans     
  0000000000  0000000000  0000000000  00000.00    00000.00    00000.00  
  usg-idle    usg-mnt     usg-inst    usg-flt     usg-cns     usg-lock    
  00000.00    00000.00    00000.00    00000.00    00000.00    00000.00  

现在我想分析它,我必须将它转换为列表或数组。我有一个用模式解析每一行的想法,但我认为有一种我不知道的简单方法。如果您有解决方案,请帮助我我想要 ac# 解决方案

4

1 回答 1

1
int counter = 0;
string line;

// Read the file and display it line by line.
using (StreamReader file = new System.IO.StreamReader("c:\\test.txt");
{
List<string> items = new List<string>();
while((line = file.ReadLine()) != null)
 {
   if (!line.Trim().StartsWith("#") && !line.Trim().StartsWith("0"))
   {
     string[] arr = line.Split('\t');  //each item
     items.Add(line);                  //or if you want the whole row
   } 

   counter++;
 }    
}
于 2013-03-09T08:23:12.403 回答