Operating System - HP-UX
1819805 Members
3191 Online
109607 Solutions
New Discussion юеВ

what is java's string continuation character?

 
SOLVED
Go to solution
Tyler Durden
Occasional Contributor

what is java's string continuation character?

I'm trying to nicely format a long java string (to fit in an 80 char editor window).

In C, I can use a backslash (\), to do something like:

char *longstring = "first line second line";

Does java have the equivalent? I get a compile error when I try:

static final String longstring = "first line second line";

Thanks in advance.
4 REPLIES 4
John Poff
Honored Contributor

Re: what is java's string continuation character?

Hi,

Have you tried this:

char *longstring = "first line second line";


JP
Tyler Durden
Occasional Contributor

Re: what is java's string continuation character?

Drats, this stupid Forums UI is replacing the backslashes with a blank space (and ignoring newlines), so my original post (and John's suggestion) were garbled.

==> Let's use "B" to represent a backslash char and "N" to represent newline char...

What I tried was:

static final String longstring = "first line BN second line";

and that gave me a javac compile error.

Any suggestions? (Please use "B" and "N" so your suggestion doesn't get Forum-mangled)...

Thanks again.
John Poff
Honored Contributor
Solution

Re: what is java's string continuation character?

Ok. Maybe you can concatenate them and do the line continuation character. Something like this:

char *longstring = "first line" + BN
"second line";


Give that a try.

JP
Michael Armbrecht
Frequent Advisor

Re: what is java's string continuation character?

Hi Tyler,

Make your string declaration look like this:

static final String longstring = ("first line "
+ "second line"
+ "third line");

Basically, use the "+" operator to concatenate part strings. Every part string can be on a separate line.
Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.