CodeItBetter Programming Another VB Programming Blog

How to Extract the Text between Two Strings in a Text file

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'Text File Handling - How to Extract the Text between Two Strings in a Text file
Public Function ExtractTextBetweenTwoStringIn_A_File(ByVal strTextFile As String, _
    ByVal strFindString1 As String, ByVal strFindString2 As String) As String
    Dim f1 As Long
    Dim strText As String
    Dim intPos As Integer
    Dim intPos1 As Integer
 
    f1 = FreeFile
    Open strTextFile For Input As f1
    strText = Input(LOF(f1), #f1)
    Close f1
 
    intPos = InStr(1, strText, strFindString1)
    intPos1 = InStr(intPos + 1, strText, strFindString2)
    strText = Mid$(strText, intPos, intPos1 - intPos)
    ExtractTextBetweenTwoStringIn_A_File = strText
End Function
'Call this function as:
'Debug.Print ExtractTextBetweenTwoStringIn_A_File("C:\temp\readme.txt", "This ", "copy a")
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.