Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Starting a new line in a string

Discussion in 'Scripting' started by greatwhiteshark17283, Aug 25, 2015.

  1. greatwhiteshark17283

    greatwhiteshark17283

    Joined:
    Feb 18, 2013
    Posts:
    15
    I'm using JS. I have a GUI Text that I want to display a list. I want to do something like this:

    Code (JavaScript):
    1. var words : GUIText;
    2. var number1 = 20;
    3. var number2 = 56;
    4. var number3 = 25;
    5.  
    6. words.text = number1+"&"+number2+"&"+number3;
    Instead of having "&", I want something that will create a new line. Is there a way to do this?
     
  2. greatwhiteshark17283

    greatwhiteshark17283

    Joined:
    Feb 18, 2013
    Posts:
    15
  3. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    \n is correct for UNIX based systems. For Mac, \r will work. On Windows, it's \r\n. Actually it's quite a mess and we have typewriters to thank.

    Easiest solution is to use
    Code (csharp):
    1. Environment.NewLine
    and let the computer figure it out.
     
    AndreaMar likes this.
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Mac is \n (being a UNIX-based system); it definitely does not use \r. Also \n works fine on Windows. So just use \n.

    --Eric
     
    Tonymotion, eisenpony and lordofduct like this.
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Yeah, just \n is fine.

    The only program I see be a wah wah about \n on its own is Notepad... and really, I haven't used Notepad in years.