Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing multiline text strings 1

Status
Not open for further replies.

siberian

Programmer
Sep 27, 2003
1,295
0
0
US
Is there an easy method of printing multi-line text?

So, instead of

out.println('Dear Sir,');
out.println('It has come to our attention that you are');
out.println('not paying your bills! This is a terrible');
out.println('and horrible thing and we think you shoud');
out.println('be aware of the hideous consequences of');
out.println('your gambling debt.');

In 'some other languages' you can just go

print <<EOF;
blalsdfaf
rfgewrgwegwegwer
gewrgwergewrgewr gwerg ewrg
wergwer gewrg werg werg werg

EOF

Is there a java equivelant?

Thanks
 
Use \n carriage returns :

System.out.println(&quot;Bla, bla \n Bla bla \n Bla bla&quot;);

Will render :

Bla bla
Bla bla
Bla bla
 
Sorry, but I don't know an equivelant to your code. But you could use an escape charater (\n) instead:

Code:
out.println(&quot;Dear Sir,\nIt has come to our attention that you are\nnot paying your bills! This is a terrible\nand horrible thing and we think you shoud\nbe aware of the hideous consequences of\nyour gambling debt.\n&quot;);

As you can see the text is hard to read now...

patrick.metz@epost.de
 
uups... sedj was quicker ;)

patrick.metz@epost.de
 
Just want to give some alternative, to make it easy when you have to write
Code:
System.out.println
several times. Because it's quite long to type it ;p

Code:
public static void printf (Object str) {
   System.out.print (str);
}

So instead of using System.out.println (or print), you can simply use the above printf function

Code:
 printf (&quot;Dear Sir,\n&quot;);
 printf (&quot;It has come to our attention that you are&quot;);
 // and so on...

Hmm.. why not try to store the string you want to print in variable first and then pass it to System.out.println or printf

Code:
String msg;

msg = &quot;Dear sir,\nIt has come to our attention that you are \nnot paying your bills!\n ....&quot;;

printf (msg);
 
out.println(
&quot;Dear Sir,\nIt has come to our attention that&quot; +
&quot;you are\nnot paying your bills! This is a terrible\nand&quot; +
&quot; horrible thing and we think you shoud\nbe aware of the&quot; +
&quot; hideous consequences of\nyour gambling debt.\n&quot;);

Ion Filipski
1c.bmp
 
I think Ion came closest to what I am looking for. Its not a 'how do I print multiple lines', its a 'how to I print multiple lines without having to type the print command a bazillion times :)

Thanks all!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top