当前位置: 代码迷 >> VB Dotnet >> vb 辨别读取txt
  详细解决方案

vb 辨别读取txt

热度:359   发布时间:2016-04-25 01:59:05.0
vb 识别读取txt
有如图大量相同格式数据单元重复   所在行数不能确定 因为单元与单元之间有别的数据
想通过识别蓝色框里的 关键词读取 他后边的数据(红色框内)一个单元的数据存储为一个数组 ,哪位大神给帮帮忙 
 ***********************************************************************************************************************************
 TIME:  7274.0 days                              I M E X   F I E L D  S U M M A R Y                               DATE: 2019:DEC:01 
 ***********************************************************************************************************************************
 ===================================================================================================================================
                                 +                     ++                     +                                                     
                                 +         WELL        ++   TOTAL FOR GROUP   +                                                     
                                 +---------------------++---------------------+                                                     
                                 + No.       Name      ++ No.       Name      +                                                     
                                 +---- ----------------++---- ----------------+                                                     
                                 +   1      Well-1     ++   1       Field     +                                                     
 --------------------------------+---------------------++---------------------+                                                     
 Well parameters                 +                     ++                     +                                                     
   Well Type                     +       Producer      ++                     +                                                     
   Status                        +          BHP        ++                     +                                                     
   On-time fraction              +          1.0        ++                     +                                                     
   Cumulative Open days          +         7274        ++         7274        +                                                     
 Well Pressures                  +                     ++                     +                                                     
   Bottom Hole     kPa           +        10000        ++                     +                                                     
   Grid Block      kPa           +        11034        ++                     +                                                     
   Drawdown        kPa           +        1033.8       ++                     +                                                     
   Ref Layer Head  kPa           +          0          ++                     +                                                     
   Tubing Head     kPa           +                     ++                     +                                                     
 Mobility Weighted Pressures     +                     ++                     +                                                     
   P-P(0)          kPa           +      -3.4346E+4     ++                     +                                                     
   Block Pressure  kPa           +        10701        ++                     +                                                     
   Datum Pressure  kPa           +        10701        ++                     +                                                     
 Inst Surface Production Rates   +                     ++                     +                                                     
   Oil              m3/day       +        6.7135       ++        6.7135       +                                                     
   Water            m3/day       +      1.41974E-3     ++      1.41974E-3     +                                                     
   Gas             M m3/day      +      6.71349E-5     ++      6.71349E-5     +                                                     
 Surface Production Rate Ratios  +                     ++                     +                                                     
   GOR              m3/ m3       +        1.0E-2       ++        1.0E-2       +                                                     
   WCUT            Percent       +      2.1143E-2      ++      2.1143E-2      +                                                     
   WGR              m3/MM m3     +        21148        ++        21148        +                                                     
 Surface cumulative production   +                     ++                     +                                                     
   Well Open Time  days          +         7274        ++         7274        +                                                     
   Oil             M m3          +        101.7        ++        101.7        +                                                     
   Water           M m3          +      1.46801E-2     ++      1.46801E-2     +                                                     
   Gas             MM m3         +      1.01704E-3     ++      1.01704E-3     +                                                     
 ===================================================================================================================================
 ===================================================================================================================================
------解决思路----------------------
一行行读取,第一个time部分应该可以直接读取,他上面应该不会有什么内容了吧,然后后面的可以通过正则匹配每行的数据是否符合特定格式
看你内容Well Parameters这种是顶行的,前面没有空格,它的子内容前面有空格,你可以通过下面的正则来匹配
^(\s*)([^\+]*)\+([\s\S]*?)(?=\+\+)
如果匹配成功,则判断m.Group[1].Value是否长度等于0,为0表示是title,否则就是子内容,m.Group[2].Value就是蓝色内容部分,m.Group[3].Value是红色部分,注意Trim
------解决思路----------------------
先读取文件所有行
做个循环
判断每一行是否包含“ Well parameters  ”
如果是,读取接下来四行的数据
读取数据直接用trim(mid(s,indexof("+"),indexof("++")-indexof("+"))
接下来判断其他各项Well Pressures 
 ……
判断是否包含“==”
是就退出循环
  相关解决方案