[ACCEPTED]-What is the syntax for new line in Objective-C?-objective-c

Accepted answer
Score: 23

Objective-C is an extension of C. So '\n' works 1 too in Objective-C.

Score: 14

It's the same (\n), but there's a lot more 39 to the topic depending on whether it's just 38 a new line or a new paragraph, what context the text 37 will be processed in, etc. From the documentation (referencing 36 the Cocoa docs here because they cover both 35 Objective-C [implicitly] and Cocoa, since 34 you have the iphone tag on your question):

There 33 are a number of ways in which a line or 32 paragraph break may be represented. Historically 31 \n, \r, and \r\n have been used. Unicode defines 30 an unambiguous paragraph separator, U+2029 (for 29 which Cocoa provides the constant NSParagraphSeparatorCharacter), and 28 an unambiguous line separator, U+2028 (for which 27 Cocoa provides the constant NSLineSeparatorCharacter).

In the Cocoa 26 text system, the NSParagraphSeparatorCharacter is treated consistently 25 as a paragraph break, and NSLineSeparatorCharacter is treated consistently 24 as a line break that is not a paragraph 23 break—that is, a line break within a paragraph. However, in 22 other contexts, there are few guarantees 21 as to how these characters will be treated. POSIX-level 20 software, for example, often recognizes 19 only \n as a break. Some older Macintosh software 18 recognizes only \r, and some Windows software 17 recognizes only \r\n. Often there is no distinction 16 between line and paragraph breaks.

Which 15 line or paragraph break character you should 14 use depends on how your data may be used 13 and on what platforms. The Cocoa text system 12 recognizes \n, \r, or \r\n all as paragraph breaks—equivalent 11 to NSParagraphSeparatorCharacter. When it inserts paragraph breaks, for 10 example with insertNewline:, it uses \n. Ordinarily NSLineSeparatorCharacter is 9 used only for breaks that are specifically 8 line breaks and not paragraph breaks, for 7 example in insertLineBreak:, or for representing HTML <br> elements.

If 6 your breaks are specifically intended as 5 line breaks and not paragraph breaks, then 4 you should typically use NSLineSeparatorCharacter. Otherwise, you 3 may use \n, \r, or \r\n depending on what other 2 software is likely to process your text. The 1 default choice for Cocoa is usually \n.

Score: 2

It's the same, but if you are printing to 1 the console, you should use

NSLog(@"This is a console statement\n on two different lines");

Hope this helps.

Score: 1

It's same dude. Objective-c is superset 2 of c so most of the things from c will work 1 in objective-c too.

Score: 1

Its same.In Objective c "\n" use for new 1 line.

More Related questions