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 › Noob question: Inserting a carriage return
Page Index Toggle Pages: 1
Noob question: Inserting a carriage return (Read 1017 times)
Noob question: Inserting a carriage return
Aug 17th, 2009, 4:42pm
 
Hello, how do I make it so

Quote:
String b = "The dog \r went home.";
text(b, 0, 50);


prints as

Quote:
The dog
went home.


instead of


Quote:
The dog went home.


?
Re: Noob question: Inserting a carriage return
Reply #1 - Aug 17th, 2009, 10:09pm
 
Like this.

Code:
PFont a0, a1;

void setup()
{
size(200, 200);
background(102);
a0 = loadFont("arial32.vlw");
a1 = loadFont("arial32.vlw");
textFont(a0, 32);
textFont(a1, 32);
}

void draw() {
String a0 = "The dog";
String a1 = "went home.";
text(a0, 0, 50);
text(a1, 0, 100);
}
Re: Noob question: Inserting a carriage return
Reply #2 - Aug 17th, 2009, 10:20pm
 
You could also use '\n' instead of '\r' for the next line character. Wink
Re: Noob question: Inserting a carriage return
Reply #3 - Aug 17th, 2009, 11:18pm
 
I like to complicate simple things.  Roll Eyes

Code:
PFont a0;

void setup()
{
size(200, 200);
background(102);
a0 = loadFont("arial32.vlw");
textFont(a0, 32);
}

void draw() {
String a0 = "The dog\nwent home.";
text(a0, 0, 50);
}
Re: Noob question: Inserting a carriage return
Reply #4 - Aug 18th, 2009, 6:44am
 
Also, jaylfk, there is no need to have two fonts in your example. Both calls to text can use the same font. The only reason you would need two fonts is if each piece of text on the screen was to be drawn with two completely different fonts.
Re: Noob question: Inserting a carriage return
Reply #5 - Aug 18th, 2009, 7:34am
 
or you can simply use a textbox as described in the example reference

PFont font;
font = loadFont("FFScala-Bold-12.vlw");
textFont(font);
String s = "The quick brown fox jumped over the lazy dog.";
text(s, 15, 20, 70, 70);

http://processing.org/reference/text_.html
Page Index Toggle Pages: 1