views:

313

answers:

1

I tried many things, i can't display multiline texts from database into uitextview, the \n characters appear as they are instead creating new lines.

NSString *aDescription2 = [NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 2) encoding:NSUTF8StringEncoding];

The problem must be here, because if i hardcode the nsstring with some \n they work.

I also tried to replace the \n with something else, just for testing. The \n chars are not replaced at all

NSString *aDescription = [aDescription2 stringByReplacingOccurrencesOfString:@"\n" withString:@"-------"];

What's happening? Thanks.

+1  A: 

Have you tried a different encoding, instead of NSUTF8StringEncoding?

Seems that the newline character is being replaced by something other than a newline and your stringByReplacing can't find them since it is looking for a newline. I suspect that maybe NSUTF8StringEncoding is escaping your \ and the n so that you get those two characters instead of a newline.

mahboudz
I tried almost all encodings, but you're right with something, \ was escaped, so now i'm replacing \\n instead \n, with a \n and works.Anyway, if there's another solution without replacing occurrences i'd like to hear. Maybe is something wrong with the database?
Cristi Băluță
I wouldn't be surprised if the database escapes the \n. Can you check that?
mahboudz
When i'm creating the sqlite i'm executing sql queries with the .read command from a database exported from phpmyadmin. each new line is represented with \r\n. Someone suggested to do something like this: insert into t values('ana are' || x'0a' || 'mere');I'll try that soon.
Cristi Băluță