NSString with \n or line break

Dave picture Dave · Mar 17, 2010 · Viewed 127.4k times · Source

Does anyone know how to use line breaks in NSString? I need to do something like this -

[NSString stringWithFormat:@"%@,\n%@", mystring1,mystring2];

Answer

Anthony F picture Anthony F · Apr 8, 2011

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];