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];
try this ( stringWithFormat has to start with lowercase)
In case \n or \r is not working and if you are working with uiwebview and trying to load html using < br > tag to insert new line. Don't just use < br > tag in NSString stringWithFormat.
Instead use the same by appending. i.e by using stringByAppendingString
In Swift 3, its much simpler
or if you are using a textView
I just ran into the same issue when overloading -description for a subclass of NSObject. In this situation I was able to use carriage return (\r) instead of newline (\n) to create a line break.
[NSString stringWithFormat:@"%@\r%@", mystring1,mystring2];
\n
is the preferred way to break a line.\r
will work too.\n\r
or\r\n
are overkill and may cause you issues later. Cocoa, has specific paragraph and line break characters for specific usesNSParagraphSeparatorCharacter
,NSLineSeparatorCharacter
. Here is my source for all the above.