|
-
Jul 25th, 2001, 02:43 PM
#1
Thread Starter
Member
Help working with Text within files
Hey everyone I have a .txt docuement I have it setup so that it will take text from one file and pull what i want to another file but on the first text file i want it to go through and find all text but look for spaces more then 2 lines of spaces if there is more then 2 line space delete the spaces because the paragraphs are spread all through the text file with hugh space gapes i am wanting to elminiate those and put txt in seperate text file. Can someone give me some examples thanks.
Robb
-
Jul 25th, 2001, 02:49 PM
#2
Member
It would be easier to help you if you DIDN'T MAKE THE THING ONE LONG SENTENCE!
And an example would be cool, too.
-
Jul 25th, 2001, 03:21 PM
#3
Fanatic Member
If those lines you're talking about are filled with literal space chars, you'll have to go through it manually probably, and throw out a line when you notice you have more than a certain number (which isn't really a good way). If the lines are simply blank lines, like someone kept pressing return in the text file, that's easier to take care of. All you'd need to do is read in your file into one string var, give it to Split(), then give that to Filter(), like this.
VB Code:
Dim strBuffer As String
Open "input.txt" For Binary As #1
strBuffer = Space$(LOF(1))
Get #1, 1, strBuffer
Close #1
'this will break the string at new lines, filter out the parts where
'two vbCrLfs were beside each other, result in a "", and then
'rejoin the lines with 1 vbCrLf for rewriting
strBuffer = Join(Filter(Split(strBuffer, vbCrLf), "", False), vbCrLf)
Open "output.txt" For Output As #1
Print #1, strBuffer
Close #1
That should filter out all the blank lines in the file provided it was just a bunch of extra lines like I'd mentioned. You could edit this a bit and give Filter an exclude string that is say, 6 spaces or something, and toss out any line that contains it. It would be easier than going through the file looking for long space sequences.
This is an update... I checked this out again to be sure, and the param of Filter() up there that is False may need to be True. I only have VB5, so I had to write my own versions of Split(), Filter() etc, and in mine, I have to give it True. It's because of what InStr returns when you search a string for "" probably.
Last edited by Kaverin; Jul 25th, 2001 at 03:30 PM.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Jul 25th, 2001, 03:26 PM
#4
Thread Starter
Member
Ok to make a long story short I have a text file here and it has a bunch of chucks of text that are spread out with bunch of spaces between. I just want to click a button and have it go through this text file and eliminate the spaces between so I can cut down on the length of this document. I just don't know the Code that it requires to do this any help would be great thanks.
Robb
-
Jul 25th, 2001, 03:29 PM
#5
Member
Do you have VB6? If you do, then you can use the Replace() function.
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
|