|
-
Dec 22nd, 2001, 09:45 PM
#1
Thread Starter
PowerPoster
A few simple string/file manipulation questions
Here's a list of a few questions I've got.
1. How do I replace the complete contents of a file with something else?
2. How do I parse HTML (eg.: Parse the <TITLE></TITLE> tags and display the contents in a text box, and loop it over, and if there's more than 1 <TITLE></TITLE> tag, load those into more textboxes.
Last edited by eiSecure; Dec 22nd, 2001 at 10:02 PM.
-
Dec 22nd, 2001, 10:01 PM
#2
1. How do I replace the complete contents of a file with something else?
Shame on you Ei shame on you
VB Code:
Dim MyTempoStr As String
Open "c:\test.txt" For Input As #1
MyTempoStr = Input(LOF(1), 1)
Close #1
MyTempoStr = Replace(MyTempoStr, vbCrLf, " ")
Open "c:\test2.txt" For Output As #1
Print #1, MyTempoStr
Close #1
-
Dec 22nd, 2001, 10:02 PM
#3
Thread Starter
PowerPoster

Now for number 2.
That's a tricky.
-
Dec 22nd, 2001, 10:04 PM
#4
Search with Instr the <TITLE> and </TITLE> and with MID take all stuff between...
-
Dec 22nd, 2001, 10:05 PM
#5
Need-a-life Member
Originally posted by DaoK
Shame on you Ei shame on you
VB Code:
Dim MyTempoStr As String
Open "c:\test.txt" For Input As #1
MyTempoStr = Input(LOF(1), 1)
Close #1
MyTempoStr = Replace(MyTempoStr, vbCrLf, " ")
Open "c:\test2.txt" For Output As #1
Print #1, MyTempoStr
Close #1
You don't need to open you file, just kill the file and write a new one with what you want.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Dec 22nd, 2001, 10:06 PM
#6
I know that because I have Close#1 but it is cool to compare after both file... It's just an example...
-
Dec 22nd, 2001, 10:10 PM
#7
Thread Starter
PowerPoster
-
Dec 22nd, 2001, 10:10 PM
#8
Thread Starter
PowerPoster
Originally posted by DaoK
Search with Instr the <TITLE> and </TITLE> and with MID take all stuff between...
It would be sooo much easier if there was a function for this...
-
Dec 22nd, 2001, 10:10 PM
#9
VB Code:
Dim theString As String
Dim startCount As Integer
Dim endCount As Integer
Dim block1 As String
Dim block2 As String
Dim i As Integer
block1 = "<Title>"
block2 = "</Title>"
theString = block1 & vbCrLf & "asdf" & vbCrLf & block2 ' That should be your html file here
startCount = 1
For startCount = 1 To Len(theString)
startCount = InStr(startCount, theString, "[Start]", vbTextCompare)
If startCount = 0 Then Exit For
endCount = InStr(startCount, theString, "[End]", vbTextCompare)
Debug.Print Mid(theString, startCount + Len(block1), endCount - (startCount + Len(block1)))
startCount = endCount
Next startCount
That will search and put in debug.print all the text between the tag
-
Dec 22nd, 2001, 10:11 PM
#10
Thread Starter
PowerPoster
Yes, but it's not good for looping.
When you loop the code, there always seems to be problems, and part of the text doesn't show up.
-
Dec 22nd, 2001, 10:16 PM
#11
VB Code:
Private Function BetweenStr(block1 As String, block2 As String) As String
Dim theString As String
Dim startCount As Integer
Dim endCount As Integer
Dim i As Integer
block1 = "<Title>"
block2 = "</Title>"
theString = block1 & vbCrLf & "asdf" & vbCrLf & block2 ' That should be your html file here
startCount = 1
startCount = InStr(startCount, theString, "[Start]", vbTextCompare)
If startCount = 0 Then Exit For
endCount = InStr(startCount, theString, "[End]", vbTextCompare)
BetweenStr = Mid(theString, startCount + Len(block1), endCount - (startCount + Len(block1)))
End Function
-
Dec 22nd, 2001, 10:17 PM
#12
Thread Starter
PowerPoster
DaoK, even WITH removing your re-declarations of block1 and block2, your code doesn't loop well.
Almost every time, I get words that are cut off by a few characters.
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
|