We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › loadStrings and linebreak
Page Index Toggle Pages: 1
loadStrings and linebreak (Read 785 times)
loadStrings and linebreak
Nov 19th, 2006, 3:41pm
 
Hello,

I'm loading text from a textfile and then I'd like to display it. How can I make a linebreak, because some strings are very long (and then they were not displayed) or how can I reduse the spaces between letters or words?


thanks,
*
Re: loadStrings and linebreak
Reply #1 - Nov 20th, 2006, 6:57am
 
Hey,

One quick solution that may work for your purposes is to use StringTokenizer to split your input into individual words, and control the text flow that way.

You can check the full javadoc at http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html

A typical use of ST would be something along the lines of:

Code:

String input; // ... whatever you need to do to load the input
int i=0;
int WORDS_PER_LINE = 10;
StringTokenizer st = new StringTokenizer(input);
while (st.hasMoreTokens()) {
if(i % WORDS_PER_LINE){ print("\n")} // or whatever
print(st.nextToken());
i++;
}


Hopefully this could be of some use, but if not, please tell me more about what you're trying to do, and I'll be sure to try and help.
Page Index Toggle Pages: 1