New line on Mac Display.newText

Hello,

I have a problem with the display.newText on a Mac simulator

i know that for window to go to another line it’s “\n” and for mac , i heard that it’s “\r”

The problem it’s when i do this on window , it works 

ex : display.newText(“Hello \n World”)

but on the mac simulator, it doesn’t work

ex: display.newText(“Hello \r World”)

Thanks

Hi @amir_go94,

You should specify a height parameter for the text “box”, so it supports multi-line text. This is outlined in the documentation for the API:

http://docs.coronalabs.com/api/library/display/newText.html

Hope this helps,

Brent

Just to add to the discussion.  Brent is right, newline’s only get processed on multi-line text’s, so a single line text \n has no meaning.

And FWIW, OS-X and iOS are built on a Unix based operating system that uses the MACH Kernel.  Android us a unix like operating system running on the Linux kernel.  All “Unix” based operating systems use \n as the new line character.

In the old day of OS 9 and before, Apple ran on their own operating system.  Their OS uses a CTRL-M (ASCII 13) or CR (Carriage Return) character for their newline separator.  This is coded as \r.  The \n for reference is the Linefeed character or CTRL-J or ASCII 10 depending on your point of view.   Windows and it’s MS-DOS history uses a combination of CR and LF to end their lines, so on Window’s its \r\n in many cases.  If you try to look at Windows files on a Unix box, you typically see a ^M at the end of each line because Unix used the ^J as it’s newline.   Now Corona SDK on Windows is built using a more Unix like library, so the \n should work just fine on the Windows simulator too.

Ahh computer history…

Ok, thanks for the rapid answer, so for Android, is it better to use the multiline text or can i just keep using the /n?

Thanks

I had similar problem with iOS. These are things I noticed. On windows and on android device ‘/n’ character works with single line text. However when I build for IOs then it didn’t work - had to make text multiline.

@amir_go04, if you want to use a newline (\n) and have the text end up on two separate lines without the \n showing up, you MUST use must provide a width to display.newText to put it in multi-line mode.

… regardless of the Operating system.

hmmm… so I see I have strange OSes :smiley:

… regardless of the operating system that the Corona app or simulator runs on.

Hi @amir_go94,

You should specify a height parameter for the text “box”, so it supports multi-line text. This is outlined in the documentation for the API:

http://docs.coronalabs.com/api/library/display/newText.html

Hope this helps,

Brent

Just to add to the discussion.  Brent is right, newline’s only get processed on multi-line text’s, so a single line text \n has no meaning.

And FWIW, OS-X and iOS are built on a Unix based operating system that uses the MACH Kernel.  Android us a unix like operating system running on the Linux kernel.  All “Unix” based operating systems use \n as the new line character.

In the old day of OS 9 and before, Apple ran on their own operating system.  Their OS uses a CTRL-M (ASCII 13) or CR (Carriage Return) character for their newline separator.  This is coded as \r.  The \n for reference is the Linefeed character or CTRL-J or ASCII 10 depending on your point of view.   Windows and it’s MS-DOS history uses a combination of CR and LF to end their lines, so on Window’s its \r\n in many cases.  If you try to look at Windows files on a Unix box, you typically see a ^M at the end of each line because Unix used the ^J as it’s newline.   Now Corona SDK on Windows is built using a more Unix like library, so the \n should work just fine on the Windows simulator too.

Ahh computer history…

Ok, thanks for the rapid answer, so for Android, is it better to use the multiline text or can i just keep using the /n?

Thanks

I had similar problem with iOS. These are things I noticed. On windows and on android device ‘/n’ character works with single line text. However when I build for IOs then it didn’t work - had to make text multiline.

@amir_go04, if you want to use a newline (\n) and have the text end up on two separate lines without the \n showing up, you MUST use must provide a width to display.newText to put it in multi-line mode.

… regardless of the Operating system.

hmmm… so I see I have strange OSes :smiley:

… regardless of the operating system that the Corona app or simulator runs on.