Can a string literal extend over several lines?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arungkumar
    New Member
    • Sep 2010
    • 1

    #1

    Can a string literal extend over several lines?

    Can a string literal extend over several lines? why or why not?
    Last edited by Niheel; Sep 6 '10, 07:33 PM. Reason: use correct spelling when posting question, also "answer the question" in the details box may come off as being very rude
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    String literal can not have new line character(\u000a). So that mean's it can not be more than a line.

    Regards
    Dheeraj Joshi

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      However, you can do something like
      Code:
      String test = "Line 1 " +
        "Line 2";
      if you want to separate your string. This will print as
      Code:
      Line 1 Line 2
      If you want to add a line break to the output as well, it would be
      Code:
      String test = "Line 1\n" +
        "Line 2";
      which would print as
      Code:
      Line 1
      Line 2
      Greetings,
      Nepomuk

      Comment

      Working...