Results 1 to 7 of 7

Thread: [RESOLVED] search then del .txt

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] search then del .txt

    if i have this file (attached)

    i need to search for a word
    if word found then
    search for "***" in next lines
    if "&" found then
    delete "***"
    copy this line in a textbox
    end if
    end if

    stop searching if empty line found



    how can i write this in vb
    Attached Files Attached Files

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: search then del .txt

    You can use the InStr function to search for a specific word in your text file.

  3. #3
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    Re: search then del .txt

    This code would work:

    VB Code:
    1. Dim strString, wordToLookFor As String
    2.  
    3. strString = Text1.Text 'Or whatever text/string you want to search
    4. wordToLookFor = "Test" 'This is what you want to look for and delete/remove
    5.  
    6. If InStr(strString, wordToLookFor) > 0 then
    7. strString = Replace$(strString, wordToLookFor, "") 'Using "" here will change the found
    8. 'word to nothing; you can put whatever you want in there to replace it
    9. 'with something else
    10. End If

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: search then del .txt

    Quote Originally Posted by om-yousif
    if i have this file (attached)

    i need to search for a word
    if word found then
    search for "***" in next lines
    if "&" found then
    delete "***"
    copy this line in a textbox
    end if
    end if

    stop searching if empty line found



    how can i write this in vb
    You can do string manipulation... but you have to be more clear in describing what you need... in your sample file, there's no "&"... and do you intend to delete just the line with "***" and retain the succeeding GLOSS line? and do you mean to update the textfile or just delete from the working data structure (array or string)?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: search then del .txt

    ohhhh
    i put & by mistake
    i didn't mean it , i mean ***

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: search then del .txt

    Like this?

    VB Code:
    1. Dim lStart As Long
    2. Dim lEnd as Long
    3.  
    4. lstart = InStr(1, textstream, "LOOK-UP WORD: " & strWord, vbTextCompare)
    5. If lstart > 0 Then
    6.    lend = InStr(lstart, textstream, "INPUT STRING: ", vbTextCompare)
    7.    If lend = 0 Then lend = Len(textstream)
    8.    lstart = InStr(lstart, textstream, "***")
    9.    If lstart < lEnd Then
    10.       lStart = InStrRev(textstream, vbCrlf, lstart)
    11.       lEnd = InStr(lStart, textstream, vbCrLf)
    12.       Text1.Text = Mid(textstream, lStart+2, lEnd - lStart - 2)
    13.       texstream = Left(textstream, lStart - 1) & Mid(textstream, lEnd)
    14.    end If
    15. End If

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: search then del .txt

    thanks all
    i'm done

Posting Permissions

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



Click Here to Expand Forum to Full Width