从文本文件中提取文本 [英] Extracting text from a text file
问题描述
我有一个文本文件,以几行注释开头,然后是文本字符串' 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
CloseEnd Sub
这篇关于从文本文件中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!