long string

Discussion in 'Java' started by Dirk Bruere at NeoPax, Jun 18, 2009.

  1. I have a requirement to define a longish (100+ char) string.
    How do I define it without having to put everything on the same line ie
    how can I break up the data to multiline format eg

    String myString = "abcdigigboasaeasvd
    ndjfvlggilugiugigf"

    --
    Dirk
    Dirk Bruere at NeoPax, Jun 18, 2009
    #1
    1. Advertising

  2. Dirk Bruere at NeoPax

    markspace Guest

    Dirk Bruere at NeoPax wrote:
    > I have a requirement to define a longish (100+ char) string.
    > How do I define it without having to put everything on the same line ie
    > how can I break up the data to multiline format eg
    >
    > String myString = "abcdigigboasaeasvd
    > ndjfvlggilugiugigf"
    >


    String myString = "abcdigigboasaeasvd" +
    "ndjfvlggilugiugigf";
    markspace, Jun 18, 2009
    #2
    1. Advertising

  3. markspace wrote:
    > Dirk Bruere at NeoPax wrote:
    >> I have a requirement to define a longish (100+ char) string.
    >> How do I define it without having to put everything on the same line
    >> ie how can I break up the data to multiline format eg
    >>
    >> String myString = "abcdigigboasaeasvd
    >> ndjfvlggilugiugigf"
    >>

    >
    > String myString = "abcdigigboasaeasvd" +
    > "ndjfvlggilugiugigf";


    So I have to break it up and concatenate.
    Thanks.

    --
    Dirk

    http://www.transcendence.me.uk/ - Transcendence UK
    http://www.theconsensus.org/ - A UK political party
    http://www.onetribe.me.uk/wordpress/?cat=5 - Our podcasts on weird stuff
    Dirk Bruere at NeoPax, Jun 18, 2009
    #3
  4. Dirk Bruere at NeoPax schrieb:
    > I have a requirement to define a longish (100+ char) string.
    > How do I define it without having to put everything on the same line ie
    > how can I break up the data to multiline format eg
    >
    > String myString = "abcdigigboasaeasvd
    > ndjfvlggilugiugigf"
    >


    If you need soemthing like heredoc in java you may use =

    Jruby
    http://blog.jayfields.com/2006/12/ruby-multiline-strings-here-doc-or.html
    http://blog.grayproductions.net/articles/working_with_multiline_strings
    http://snipplr.com/view/5432/ruby-heredoc-tricks/


    or Groovy which has a """ multiline String , f.e.
    String itext ="""This is another multiline String
    that takes up a few lines.

    Heredocs are different than Java Strings
    in a few important ways:
    1. They
    preserve
    newlines.

    2. You don't have to "escape" internal quotes.
    """



    within your Java code.

    Regards, Gilbert
    Gilbert Rebhan, Jun 18, 2009
    #4
  5. Dirk Bruere at NeoPax

    Roedy Green Guest

    On Thu, 18 Jun 2009 19:40:10 +0100, Dirk Bruere at NeoPax
    <> wrote, quoted or indirectly quoted someone who
    said :

    >I have a requirement to define a longish (100+ char) string.
    >How do I define it without having to put everything on the same line ie
    >how can I break up the data to multiline format eg


    String myString = "abcdigigboasaeasvd"
    + "ndjfvlggilugiugigf"

    The concatenation is done at compile time and hence has no run-time
    penalty.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    If everyone lived the way people do in Vancouver, we would need three more entire planets to support us.
    ~ Guy Dauncey
    Roedy Green, Jun 19, 2009
    #5
    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. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    659
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,178
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    461
    santosh
    Jul 24, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    782
    Peter Nilsson
    Jan 15, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,776
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page