views:

604

answers:

2

I've been searching for an answer to this question on google and some other forums, but I haven't found the answer yet. It seems like a simple enough question: how do I manually insert a newline into UITextView's text field?

If it matters, I'm reading my string from an SQLite database. That means that I'm translating a const char (I think - at least I've been casting it as such) into an NSString before I use it in UITextView's -setText. I've tried inserting '\n' into the SQLite database, but after everything is translated and assigned it comes back as '\n' on the iPhone screen. Is there another character I can use?

+2  A: 

Escape sequences in strings are interpreted at compile time and replaced with their actual byte value - therefore they have no meaning outside of the compiler.

Passing the string as it came out of your database to [UITextView setText:] is all you need to do. Your database should be holding line breaks as-is (0x0A).

Andrew

Andrew
Thanks for such a clear answer! Do you know of any way to insert a line-break into sqlite in a query with text? i.e. what should <text> be to include a linebreak in 'insert into table (text_column) values ("<text>")'?
JoBu1324
No problem. Just put a line break in between the single quotes. May look weird but its valid.insert into table (text_column) values ('first line<CR>second line')
Andrew
A: 

This didnt work for me, can you please help me here?

Futur
I never actually tested Andrew's code (which is why I never selected his answer), so I'm afraid I can't help you.
JoBu1324