Multiline quotes - escaping quotes - et al

Discussion in 'Java' started by Lawrence Tierney, Dec 24, 2003.

  1. 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
     
    Lawrence Tierney, Dec 24, 2003
    #1
    1. Advertising

  2. Lawrence Tierney <>
    wrote on 24 Dec 2003 02:39:58 -0800:
    > 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.

    --
    <a href="http://kuoi.asui.uidaho.edu/~kamikaze/"> Mark Hughes </a>
    "God, I think. God. He doesn't answer, and I'd be justifiably scared--but not
    in a panic!--if he did, since I would know it really was Resuna, or a tiny
    brain tumor, or some boo-boo in my mix of neurotransmitters." -John Barnes
     
    Mark 'Kamikaze' Hughes, Dec 24, 2003
    #2
    1. Advertising

  3. Lawrence Tierney wrote:
    > 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.
     
    Michael Borgwardt, Dec 24, 2003
    #3
  4. "Lawrence Tierney" <> wrote in message
    news:...

    > 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. ;-)

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
     
    Andrew Thompson, Dec 24, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DartmanX
    Replies:
    1
    Views:
    3,496
    Chris Smith
    Jan 23, 2005
  2. John Salerno

    escaping quotes

    John Salerno, Feb 28, 2006, in forum: Python
    Replies:
    2
    Views:
    363
    John Salerno
    Feb 28, 2006
  3. cesco

    escaping only double quotes

    cesco, Aug 31, 2007, in forum: Python
    Replies:
    2
    Views:
    282
    iapain
    Aug 31, 2007
  4. dale zhang
    Replies:
    8
    Views:
    458
    Tintin
    Nov 30, 2004
  5. Replies:
    7
    Views:
    197
    Thomas 'PointedEars' Lahn
    May 17, 2005
Loading...

Share This Page