Results 1 to 5 of 5

Extract small string of text from larger string

Threaded View

  1. #1
    Registered User
    Join Date
    06-12-2008
    Posts
    11

    Extract small string of text from larger string

    I知 working on a bit of code that I want to extract a small piece of text form a larger text file.

    At the moment I can open and read the entire text file and also pin point a start and end marker of the text I want to extract.

    What I知 having trouble doing is creating a variable text string which contains the text between the 2 markers.

    What I have so far is

    
    Function ExtractText()
    Dim sSearchText1 As String
    Dim sSearchText2 As String
    Dim sFileName As String
    Dim sFileText As String
    Dim strText As String
    
    Dim strStart As Integer
    Dim strEnd As Integer
    
    Const ForReading = 1
    
    sSearchText1 = "--**Part1**" ' start point
    sSearchText2 = "--**Part2**" 'end point
    
    sFileName = "C:\Scripts\Script.sql"
    
    'Create instance of FileSystemObject.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objfile = objFSO.OpenTextFile(sFileName, ForReading)
    
    'read entire contents of file, save to strText variable
    strText = objfile.ReadAll
    
    strStart = InStr(strText, sSearchText1)
    strEnd = InStr(strText, sSearchText2)
    
    End Function
    Last edited by mark_jam3s; 09-23-2010 at 05:34 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1