I can usually figure most things out on my own but this here issue has had me stumped for quite some time.
Given the above text, I have no problem removing the lines of text pertaining to Apple. I would use something like this:
However, in the instances I actually want to use this code the data is not 100 unique. My file would look like this:
If I ran the code above, my out put would be this:
How could I remove only Apple and its attributes? I tried setting the variable to:
Using WScript.Echo outputs the variable perfectly but it will not work in the code above. I tried using Replace but then I get a text file with blank lines. I can't figure out how to delete the blank lines.
Any ideas would be appreciated.
Code:
Apple
Fruit
Sweet
Onion
Vegetable
Savory
Given the above text, I have no problem removing the lines of text pertaining to Apple. I would use something like this:
Code:
Const ForReading = 1
Const ForWriting = 2
Dim objFSO, objFile
Dim strFile, strTxt1, strTxt2, strTxt3, strAll, strTxtN
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFile = "C:\TEMP\TNS_Test\TNSNAMES.ORA"
strTxt1 = "Apple"
strTxt2 = " Fruit"
strTxt3 = " Sweet"
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
Do Until objFile.AtEndOfStream
strAll = objFile.ReadLine
If (inStr(strAll, strTxt1) = 0 _
AND inStr(strAll, strTxt2) = 0 _
AND inStr(strAll, strTxt3) = 0) Then
strTxtN = strTxtN & strAll & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
objFile.Write strTxtN
objFile.Close
However, in the instances I actually want to use this code the data is not 100 unique. My file would look like this:
Code:
Apple
Fruit
Sweet
Onion
Vegetable
Savory
Banana
Fruit
Sweet
Tomato
Fruit
Savory
If I ran the code above, my out put would be this:
Code:
Onion
Vegetable
Savory
Banana
Tomato
Savory
How could I remove only Apple and its attributes? I tried setting the variable to:
Code:
strTxt = "Apple" & vbCrLf & _
" Fruit" & vbCrLf & _
" Sweet"
Using WScript.Echo outputs the variable perfectly but it will not work in the code above. I tried using Replace but then I get a text file with blank lines. I can't figure out how to delete the blank lines.
Any ideas would be appreciated.