比如有一个文本文件,其结构为
%block1%
....
%block2%
....
%block3%
....怎么写一个函数能返回制定段落的内容?假设 fstring=ffunciton(block1)就能返回
%block1%和%block2%之间的内容?

解决方案 »

  1.   

    funciton ffunciton(block1 as string) as string
    Dim fso As New FileSystemObject, fil As TextStream
    Set fil = fso.OpenTextFile(App.Path & "\filename.txt")
    do while not fil.AtEndOfLine
     if block1= fil.ReadLine 
       ffunciton=fil.ReadLine then 
     else
       if not fil.AtEndOfLine then 
          fil.SkipLine
       else
          ffunciton="找不到指定段!"
      end if
     end if
    loop
    end function
      

  2.   

    上面的少了一句
    funciton ffunciton(block1 as string) as string
    Dim fso As New FileSystemObject, fil As TextStream
    Set fil = fso.OpenTextFile(App.Path & "\filename.txt")
    do while not fil.AtEndOfLine
     if block1= fil.ReadLine then
       ffunciton=fil.ReadLine  
       exit do
     else
       if not fil.AtEndOfLine then 
          fil.SkipLine
       else
          ffunciton="找不到指定段!"
      end if
     end if
    loop
    end function
      

  3.   

    对txt文件的处理没什么太好的方法,只能按行来判断