Does anyone know how to use line breaks in NSString? I need to do something like this -
[NSString stringWithFormat:@"%@,\n%@", mystring1,mystring2];
Does anyone know how to use line breaks in NSString? I need to do something like this -
[NSString stringWithFormat:@"%@,\n%@", mystring1,mystring2];
\n\r seems working for me.
I am using Xcode 4.6 with IOS 6.0 as target. Tested on iPhone 4S. Try it by yourself.
Feng Chiu
If your string is going in a UIView (e.g a UILabel), you also need to set the number of lines to 0
I found that when I was reading strings in from a
.plist
file, occurrences of"\n"
were parsed as"\\n"
. The solution for me was to replace occurrences of"\\n"
with"\n"
. For example, given an instance ofNSString
namedmyString
read in from my.plist
file, I had to call...... before assigning it to my
UILabel
instance...Line breaks character for NSString is \r
correct way to use
[NSString StringWithFormat:@"%@\r%@",string1,string2];
\r ----> carriage return