How do I add a line break into a string

should be easy but can’t anything using search

Is it possible to add a line break in a string so it can print on two lines e.g.

string = “First \n Second” or the
html tag

I used the \n as that should be a new paragraph but that didn’t work, all I need is the text to be formed under the 1st line.

Thanks [import]uid: 3093 topic_id: 15148 reply_id: 315148[/import]

I was searching the forums for pretty much the same problem that I am experiencing and came across your post. I’m having the same issues where \n should cause a line break but doesn’t… funny thing is, it works just like it should on my windows computer but not on my mac… dunno, I’m using exact same code too. [import]uid: 50005 topic_id: 15148 reply_id: 56348[/import]

What are you using for your output? The console using print()? A native text box? Or a text field made with display.newText().

print() - uses “\n”
native.newTextBox() - this also uses “\n”

display.newText() - no such option. You have to write your own text wrapping system. This method only creates a single line at a time. Anything too wide just doesn’t get displayed past the edge of the screen.

Hope that helps. [import]uid: 10818 topic_id: 15148 reply_id: 56351[/import]

oh I see…

I was using display.newText

It for some reason worked on my windows machine which through me off as to why it wasn’t working on my Mac. Thanks for the tip! Much appreciated [import]uid: 50005 topic_id: 15148 reply_id: 56424[/import]

@ibknepper: I primarily work on a Win 7 machine… build and test with simulator… then switch to Mac for final phase when building out to iPhone. What version of Corona are you working with? Are you using a daily build? I have never seen display.newText() create a second line, but if you have seen that, then maybe Ansca is working on a multi-line text box feature? In which case, I want to know more! :slight_smile: Can you tell me anything that I can do to reproduce this?

Thanks! [import]uid: 10818 topic_id: 15148 reply_id: 56433[/import]

I’m currently using version .591 so to answer your question… no I’m not using daily builds (currently waiting until my app is a little further along before I purchase a sub). My other machine is a windows vista laptop. Here is an example of the code I was using to give you an idea…

[code]
–this will change depending on other things going on within the game
local condition = 1

–this holds my strings to be later displayed on screen as text
local textSelection = {
“Line one of text goes here \n Line Two of text will appear directly below”,
“This is the second display of text \n with a line break depending on what condition is”
}

–this piece of text will display one the strings from the textSelection array depending on whether condition is 1 or 2
local text = display.newText(textSelection[condition], 0, 0, native.systemFont, 35)
[/code] [import]uid: 50005 topic_id: 15148 reply_id: 56444[/import]

@Ibknepper:

Interesting-- I thought you were maybe using the latest daily build… I should have just run a quick test on my own (but deadlines are keeping me busy)… I haven’t checked this in quite a while… so it looks like Corona is on the way to doing text wrapping in the display.newText() objects. Very cool. Next time I fire up the mac I’ll see if it works there, too.

Thanks for the extra info! [import]uid: 10818 topic_id: 15148 reply_id: 56447[/import]

Thanks for response especially you duneit.

Documentation again is very sparse on displaying text. So you can’t do this with display.NewText

Actually I am using Text Candy and with a bit more digging you can use the vertical line character | to break a line.

I use TextCandy for bitmaps as well as vector fonts and overall it has been good value for money. I was driven towards this solution as the vector font docs in Corona weren’t particularly clear on installing new fonts.

Again with hindsight get your photoshop jockey to prepare your text screens for games it will save you in the long run. [import]uid: 3093 topic_id: 15148 reply_id: 56481[/import]