Multiline quotes - escaping quotes - et al

L

Lawrence Tierney

G'day,

I'm moving over from Perl to Java *cof cof*. So two questions:

1. Does Java have a multiline quote like Perl's "here documents" i.e.

<<HTML;

<table cellpadding="0" cellspacing="0" align="center">
<tr>
<td>Oh for a multiline quote!!</td>
</tr>
</table>

HTML

2. Does Java have a quote escaper a la Perl's qq function?

Perl: $html=qq*<td align="center" bgcolor="#ffffff">No need to escape</td>*;
Java: String html="<td align=\"center\" bgcolor=\"#ffffff\">No need to escape</td>";

Surely Java must have mechanisms for both of the above?

Lord0
 
M

Mark 'Kamikaze' Hughes

Lawrence Tierney said:
G'day,
I'm moving over from Perl to Java *cof cof*. So two questions:
1. Does Java have a multiline quote like Perl's "here documents" i.e.
<<HTML;
<table cellpadding="0" cellspacing="0" align="center">
<tr>
<td>Oh for a multiline quote!!</td>
</tr>
</table>
HTML
2. Does Java have a quote escaper a la Perl's qq function?
Perl: $html=qq*<td align="center" bgcolor="#ffffff">No need to escape</td>*;
Java: String html="<td align=\"center\" bgcolor=\"#ffffff\">No need to escape</td>";
Surely Java must have mechanisms for both of the above?

Nope. The usual solutions are:

1) Write your XML/HTML using ' instead of ", then use (in vi, adapt to
your editor of choice) :'a,.s/^.*$/"&\\n",/

2) Store text like that in separate files and use a utility method
to read it in, then do string replacement to insert values. This is a
better solution than hardcoding a bunch of text, but does require a bit
more work. At the end of this, you'll have a generalized templating
system, though, which is handy.
 
M

Michael Borgwardt

Lawrence said:
Surely Java must have mechanisms for both of the above?

Nope. What it does have is JSP, which completely removes the need
for such ugly mixes of markup and program code.
 
A

Andrew Thompson

1. Does Java have a multiline quote like Perl's "here documents" i.e. ....
<td>Oh for a multiline quote!!</td>
[ Oh for an online tutorial!!
http://java.sun.com/docs/books/tutorial/ ]


I do not understand why you are putting html, but..
String s = "this" +
"this and this and this as wel as these (things)" +
"this and this and this as wel as these (things)";
2. Does Java have a quote escaper a la Perl's qq function?
http://java.sun.com/products/jndi/tutorial/beyond/names/syntax.html

Surely Java must have mechanisms for both of the above?

We have donuts in _all_ the
colors of the rainbow. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top