Question

I have a varchar column in an sqlite datbase. A particular row of text has a backslash, which is used with "\n" for a carriage return in a UITextView. When the value is read from the database via a SELECT:

myobject.text = [NSString stringWithUTF8String: (char *)sqlite3_column_text(selectstmt, 2)];

The backslash is escaped and looks like:

"\\n" rather than "\n"

which doesn't interpret as a carriage return. If I add two blackslashes in the text, the second will also be escaped and eventually leads to an exception when the textview is added as a subview:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key test.'

Is there a way to prevent these escapes or will I need to clean it up manually?

Was it helpful?

Solution

The backslash is no doubt right there in the column's text -- you're "seeing" it as doubled because that's how backslashes are shown (to avoid confusion with escape sequences). sqlite is not altering the text you put there when you query it -- but arguably, the text that's in the database is not what you want to receive.

What you need to do is to change the two characters backslash-n into the single character newline, and you can to that either in the database (once and for all, or on each query) or in your objective-C code (on each query) depending on your exact needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top