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
Printable View
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 use the InStr function to search for a specific word in your text file.
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
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)?Quote:
Originally Posted by om-yousif
ohhhh
i put & by mistake
i didn't mean it , i mean ***
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
thanks all
i'm done