Results 1 to 5 of 5

Thread: Help working with Text within files

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Nebraska
    Posts
    46

    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

  2. #2
    It would be easier to help you if you DIDN'T MAKE THE THING ONE LONG SENTENCE!

    And an example would be cool, too.

  3. #3
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    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:
    1. Dim strBuffer As String
    2. Open "input.txt" For Binary As #1
    3. strBuffer = Space$(LOF(1))
    4. Get #1, 1, strBuffer
    5. Close #1
    6. 'this will break the string at new lines, filter out the parts where
    7. 'two vbCrLfs were beside each other, result in a "", and then
    8. 'rejoin the lines with 1 vbCrLf for rewriting
    9. strBuffer = Join(Filter(Split(strBuffer, vbCrLf), "", False), vbCrLf)
    10. Open "output.txt" For Output As #1
    11. Print #1, strBuffer
    12. 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

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Nebraska
    Posts
    46
    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

  5. #5
    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
  •  



Click Here to Expand Forum to Full Width