[ACCEPTED]-What is the syntax for new line in Objective-C?-objective-c
Objective-C is an extension of C. So '\n' works 1 too in Objective-C.
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 constantNSParagraphSeparatorCharacter
), and 28 an unambiguous line separator,U+2028
(for which 27 Cocoa provides the constantNSLineSeparatorCharacter
).In the Cocoa 26 text system, the
NSParagraphSeparatorCharacter
is treated consistently 25 as a paragraph break, andNSLineSeparatorCharacter
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 toNSParagraphSeparatorCharacter
. When it inserts paragraph breaks, for 10 example withinsertNewline
:, it uses\n
. OrdinarilyNSLineSeparatorCharacter
is 9 used only for breaks that are specifically 8 line breaks and not paragraph breaks, for 7 example ininsertLineBreak
:, 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
.
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.
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.
Its same.In Objective c "\n" use for new 1 line.
Straight from the dragons mouth. http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/Strings/Articles/stringsParagraphBreaks.html
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.