Dec 3rd, 2006, 05:34 PM
#1
Thread Starter
Addicted Member
[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
Dec 3rd, 2006, 06:37 PM
#2
Re: search then del .txt
You can use the InStr function to search for a specific word in your text file.
Dec 3rd, 2006, 08:54 PM
#3
Hyperactive Member
Re: search then del .txt
This code would work:
VB Code:
Dim strString, wordToLookFor As String
strString = Text1.Text 'Or whatever text/string you want to search
wordToLookFor = "Test" 'This is what you want to look for and delete/remove
If InStr(strString, wordToLookFor) > 0 then
strString = Replace$(strString, wordToLookFor, "") 'Using "" here will change the found
'word to nothing; you can put whatever you want in there to replace it
'with something else
End If
Dec 4th, 2006, 06:44 AM
#4
Re: search then del .txt
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)?
Dec 4th, 2006, 07:02 AM
#5
Thread Starter
Addicted Member
Re: search then del .txt
ohhhh
i put & by mistake
i didn't mean it , i mean ***
Dec 4th, 2006, 07:56 AM
#6
Re: search then del .txt
Like this?
VB Code:
Dim lStart As Long
Dim lEnd as Long
lstart = InStr(1, textstream, "LOOK-UP WORD: " & strWord, vbTextCompare)
If lstart > 0 Then
lend = InStr(lstart, textstream, "INPUT STRING: ", vbTextCompare)
If lend = 0 Then lend = Len(textstream)
lstart = InStr(lstart, textstream, "***")
If lstart < lEnd Then
lStart = InStrRev(textstream, vbCrlf, lstart)
lEnd = InStr(lStart, textstream, vbCrLf)
Text1.Text = Mid(textstream, lStart+2, lEnd - lStart - 2)
texstream = Left(textstream, lStart - 1) & Mid(textstream, lEnd)
end If
End If
Dec 4th, 2006, 12:50 PM
#7
Thread Starter
Addicted Member
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width