从文本文件中提取文本 [英] Extracting text from a text file

查看:116
本文介绍了从文本文件中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,以几行注释开头,然后是文本字符串' FESTWERT'


我想从'FESTWERT'的第一个实例中提取所有内容直到文本文件结尾并将其放入另一个文件中。



有人可以帮助我吗?

解决方案

您好



假设有换行符下面的文本文件应该让你开始,只需更改文件名/路径:



公开子例子()
Dim FN1,FN2 As Long
Dim strLineOfText As String
Dim blnTextFound As Boolean



blnTextFound = False
FN1 = FreeFile()
打开" c:\ myInputFile.txt"对于输入为FN1
FN2 = FreeFile()
打开"c:\ myOutputFile.txt"对于输出为FN2
而非EOF(FN1)
线输入#FN1,strLineOfText
如果左


(strLineOfText,8)=" FESTWERT"然后blnTextFound = True
如果blnTextFound然后打印#FN2,strLineOfText
Wend
关闭


End Sub


 I have a text file which begins with a few lines of comments and then is followed by the text string 'FESTWERT'

 

I want to extract everyting from the first instance of 'FESTWERT' till the end of the textfile and put this in another file.

 

Can somebody help me??

解决方案

Hi

 

Assuming that there are line feeds in your text file the below should get you started, just change the file names / paths:

 

Public Sub EXAMPLE()
Dim FN1, FN2 As Long
Dim strLineOfText As String
Dim blnTextFound As Boolean

 

blnTextFound = False
FN1 = FreeFile()
Open "c:\myInputFile.txt" For Input As FN1
FN2 = FreeFile()
Open "c:\myOutputFile.txt" For Output As FN2
While Not EOF(FN1)
    Line Input #FN1, strLineOfText
    If Left


(strLineOfText, 8) = "FESTWERT" Then blnTextFound = True
    If blnTextFound Then Print #FN2, strLineOfText
Wend
Close

End Sub


这篇关于从文本文件中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆