Problem with \t \n with NSString - iphone

I have a plist where I place my strings, with type string.
When I access the strings in the plist, it doesnt interpret \n and \t.
So when I display these strings it will display \tTitle
and not Title with tab indention.
But if I use
#define str1 #"\tTitle"
and just place it in header files, it works.
Please help.

Maybe something is wrong with the way you are accessing the string. Take a look here: Property list programming guide

Related

How to set line linebreak when passing parameters to Facebook

I am passing parameters to Facebook using JSON concept.I am passing Location name and Date in that. After location name i want to display Date in new line.Can any one help me how to give line break. Here is the my code.
Thanks in Advance.
NSString *att=[NSString stringWithFormat:#"{\"name\":\"%#\","
"\"href\":\"%#\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"%#\","
"\"href\":\"%#\"}],"
"\"properties\":{\"Location\":\"%#\"\" Date\":\"%#\"}}",eventTitle.text,href,imageSource,imageHref,eventLocation.text,eventDate.text];
Not really a Facebook question. But certainly HTML-escaped spaces won't work.
You're probably looking for an escaped newline, \n
In fact, you'll need to escape it twice: once for NSString and once for JSON, ending up \n in your code

How to parse special characters in XML for iPad?

I am getting problem while parsing xml files that contains some special characters like single quote,double quote (', "")etc.I am using NSXMLParser's parser:foundCharacters:method to collect characters in my code.
<synctext type = "word" >They raced to the park Arthur pointed to a sign "Whats that say" he asked Zoo said DW Easy as pie</synctext>
When i parse and save the text from above tag of my xml file,the resultant string is appearing,in GDB, as
"\n\t\tThey raced to the park Arthur pointed to a sign \"Whats that say\" he asked Zoo said DW Easy as pie";
Observe there are 2 issues:
1)Unwanted characters at the beginning of the string.
2)The double quotes around Whats that say.
Can any one please help me how to get rid of these unwanted characters and how to read special characters properly.
NSString*string =[string stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#" \n\t"]];
The parser is apparently returning exactly what's in the string. That is, the XML was coded with the starting tag on one line, a newline, two tabs, and the start of the string. And quotes in the string are obviously there in the original (and it's not clear in at least this example why you'd want to delete them).
But if you want these characters gone then you need to post-process the string. You can use Rams' statement to eliminate the newline and tabs, and stringByReplacingOccurrencesOfString:WithString: to zap the quotes.
(Note that some XML parsers can be instructed to return strings like this with the leading/trailing stuff stripped, but I'm not sure about this one. The quotes will always be there, though.)

UITableViewCell newline characters

Is there any way to get newlines to be converted to actual linebreaks in UITableViewCell?
Right now they show up as \r\n (they come from a sqlite3 db) and just get displayed as such.
If I search and replace \r\n with actual return characters then it works fine, but I'm wondering if three is a proper way to do this?
Please don't suggest using other View types, the app is basically 100% complete save for this last bug and I don't want to re-test everything.
thanks
T
edit: Solution in case anyone has a similar issue:
cellText = [cellText stringByReplacingOccurrencesOfString:#"\\r\\n" withString:#"\n"];
Olaf got me on the right path, thanks.
IIRC on the Mac newline is \n, but this is not the question.
If you are seeing the four characters "\r\n" on the screen then I assume the string coming from db is escaping the backslashes. Thus when you do the manually rewrite the (escaped) string \\r\\n is converted into \n.
The standard cell is using an embedded UILabel anyway, so rewriting your cell with a custom cell using another UILabel would not change much. ;)
I just finished fixing this very issue in my code using:
myString = [[myString
stringByReplacingOccurrencesOfString:#"\\\\n" withString:#"\n"]
stringByReplacingOccurrencesOfString:#"\\\\r" withString:#""];
Hope that helps

Emoji iCons are not displaying correctly when read from plist

I am trying to read some text from a plist file and display it to the users in alert box.
When I build the string using this code, everything works (users sees Hello with a smily icon):
NSString *hello = #"Hello \ue415";
but when I get the string from plist, using this code, uses sees "Hello \ue415":
NString *hello = (NSString *)[pageLiteratureDic objectForKey:litratureKey];
Do I have to encode string differently? Any help or pointers will be much appreciated... everyone love emojis ;)
You shouldn't literally type "\ue415" as text into the plist file. \u.... is an escape sequence in the syntax of strings and characters in the C language. The string itself does not contain backslash and "u" and whatever, it contains just 1 character, the Unicode character at the codepoint 0xe415. If you want to save that in a plist, you have to manually type that one Unicode character in there yourself, making sure to use whatever encoding that is required of a plist (maybe utf-8 or utf-16, not sure). Alternately, you can write a program that creates a plist from that string, and then copy and paste whatever is in that plist file over to your file.
In the plist, instead of "Hello \ue415" try using the smily face character explicitly as in "Hello :)". Just cut and paste the smily character over the unicode code. The reading of the plist is probably escaping the backslash and stopping the interpretation as a unicode character.

\n is not working in plist?

I created array.plist file where I am storing key value pair
e.g
key = MY_FIRST_MESSAGE
Value = Welcome\n I am happy to serve you.
in xml format
Welcome\n I am happy to serve you.
I received this sting in dictionary and display in textview like below code
textView.text = [myDict objectForKey:MY_FIRST_MESSAGE];
But
I am not able to get newline. It should be look like below
Welcome
I am happy to serve you
But I got it like
Welcome\n I am happy to serve you
On textview view,
I debug this problem, my got string from plist is like Welcome\n I am happy to serve you.
Please suggest me how to remove \n from string which are from plist?
I tried \n, /n, /\n all combination.
Thanks
Manu
.plist files are XML, so you should be able to use an actual newline character rather than the string "\n".
Failing that:
string = [string stringByReplacingOccurrencesOfString:#"\\n" withString:#"\n"];