• Post Reply Bookmark Topic Watch Topic
  • New Topic

formating outFile

 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, I am writing a text file from a string. When I do this, it just writes it all in one big line with out any returns. I've created some code that inserts an outFile.println() every 60 characters, but when I do this it breaks up words. So now I am trying to write something that won't break the words up, but I can't quite get it right. This is what I have so far, but it doesn't work. Thanks in advance for your help.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done something like this in the past to "flow" text into new margins. I think that's what you're after, no?

There is no built-in "get a word" function. You might put all your text into one string and split on blank or read from a stream a character at a time until you get whitespace. Does that sound useful?

BTW: I got way complex and supported margin parameters - say flow between columns 5 and 70 - and the abilitiy to indent or outdent the first line of a paragraph, or even insert blanks to make every line exactly fill the margins. There's lots of fun to be had fer sure.
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You might put all your text into one string and split on blank or read from a stream a character at a time until you get whitespace. Does that sound useful?

That is exactly what I am trying to do with the code above, just for some reason I can't get it to work. I have a very long string that I am atempting to make into a text file that isn't one extremly long line. The code above should print the first 60 characters and the start searching for the first blank space, when it finds it, it should break the while loop, insert a outFile.println() and then go back to the begining of the for loop. When I look at the code above I can't figure out why it doesn't work. Thanks for your help
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well guys I got it, it looks like this:

Thanks again Stan
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd still make a function that returns a word at a time from your string. That separates checking for spaces from checking line length. I could remove the line variable from my little algorithm and write straight to output like you do:

This may take a little more tweaking to put spaces between words but not at the end of line.
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ill try that, thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!