Can anyone tell me what is the symbol used for new line?
In the C language we use '\n'
for new line. What do we use in Objective-C?
is it same开发者_Go百科?
Objective-C is an extension of C. So '\n' works too in Objective-C.
It's the same (\n
), but there's a lot more to the topic depending on whether it's just a new line or a new paragraph, what context the text will be processed in, etc. From the documentation (referencing the Cocoa docs here because they cover both Objective-C [implicitly] and Cocoa, since you have the iphone
tag on your question):
There are a number of ways in which a line or paragraph break may be represented. Historically
\n
,\r
, and\r\n
have been used. Unicode defines an unambiguous paragraph separator,U+2029
(for which Cocoa provides the constantNSParagraphSeparatorCharacter
), and an unambiguous line separator,U+2028
(for which Cocoa provides the constantNSLineSeparatorCharacter
).In the Cocoa text system, the
NSParagraphSeparatorCharacter
is treated consistently as a paragraph break, andNSLineSeparatorCharacter
is treated consistently as a line break that is not a paragraph break—that is, a line break within a paragraph. However, in other contexts, there are few guarantees as to how these characters will be treated. POSIX-level software, for example, often recognizes only\n
as a break. Some older Macintosh software recognizes only\r
, and some Windows software recognizes only\r\n
. Often there is no distinction between line and paragraph breaks.Which line or paragraph break character you should use depends on how your data may be used and on what platforms. The Cocoa text system recognizes
\n
,\r
, or\r\n
all as paragraph breaks—equivalent toNSParagraphSeparatorCharacter
. When it inserts paragraph breaks, for example withinsertNewline
:, it uses\n
. OrdinarilyNSLineSeparatorCharacter
is used only for breaks that are specifically line breaks and not paragraph breaks, for example ininsertLineBreak
:, or for representing HTML<br>
elements.If your breaks are specifically intended as line breaks and not paragraph breaks, then you should typically use
NSLineSeparatorCharacter
. Otherwise, you may use\n
,\r
, or\r\n
depending on what other software is likely to process your text. The default choice for Cocoa is usually\n
.
It's the same, but if you are printing to 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 of c so most of the things from c will work in objective-c too.
Its same.In Objective c "\n" use for new line.
Straight from the dragons mouth. http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/Strings/Articles/stringsParagraphBreaks.html
精彩评论