CRLF / LF in text objects

I'm attempting to create a new text object (display.newText) and the text string contains crlfs.

On windows, I use \r\n and everything looks great. On the Mac, there are no crlfs at all. I can't figure out how to get a newline to appear.

How do I write for multiplatform if the crlfs are not standard?

What do I use on Mac to get a new line?

jchinkle,

I am getting garbage characters no matter what I use for my newlines when I run on the Android emulator. (Works fine in the Corona simulator though.) What are your running on that \r\n works?

Thank you

OK, I did a little testing using this:

--------------------------------
-- Text test for Android
--------------------------------

str1 = "Aa \n Bb"
str2 = " "

len1 = #str1

for i = 1, len1 do
local c = str1:sub(i,i)
local n = tonumber(string.byte(c))
str2 = str2.." "..string.format("%2d",n)
end

testText1 = display.newText(str1, 0, 0, native.systemFont, 25 )
testText1.x = display.contentWidth/2
testText1.y = display.contentHeight/4
testText1:setTextColor( 255, 255, 255)

testText2 = display.newText(str2, 0, 0, native.systemFont, 25 )
testText2.x = testText1.x
testText2.y = testText1.y + 50
testText2:setTextColor( 255, 255, 255)

It prints out the string, and the ASCII values for it. On linux-ish machines, you would expect to see a LF, or 10d to get the new line. (Mac CR or 13d, and Windows CRLF)

I ran the program in the Corona simulator, and the '\n' worked just fine, it showed up as ASCII 10d, as expected. When I ran the same program from a build in the Android emulator, the '\n' did not work, (Got a garbage character box) but the ASCII showed
10d as expected. I also made a 'real' android build that did the same program, but in Java/Eclipse. The '\n' worked there, and the ASCII character was again 10d.

So in summary, '\n' should work for the new line. But it does not seem to work when you build and run for Android in Corona. I think I need a Corona grown up at this point to explain this to me. :-)

display.newText does not support displaying text on multiple lines. If you want text displayed on two lines, you need to use two display.newText commands.

The native.newTextBox does support embedding "\n" characters to start a new line. http://developer.anscamobile.com/reference/index/nativenewtextbox

Tom

views:1927 update:2011/10/3 8:06:12
corona forums © 2003-2011