简体   繁体   English

Objective-C中新行的语法是什么?

[英]What is the syntax for new line in Objective-C?

Can anyone tell me what is the symbol used for new line? 谁能告诉我新线的符号是什么?

In the C language we use '\\n' for new line. 在C语言中,我们使用'\\n'作为新行。 What do we use in Objective-C? 我们在Objective-C中使用了什么?

is it same? 是一样的吗?

Objective-C是C的扩展。所以'\\ n'也适用于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): 它是相同的( \\n ),但是主题还有很多,这取决于它只是一个新还是一个新段落 ,文本将被处理的上下文等等。从文档中引用(这里引用Cocoa文档,因为它们涵盖了Objective-C [隐式]和Cocoa,因为你的问题上有iphone标签):

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. 历史上已使用\\n\\r\\r\\n Unicode defines an unambiguous paragraph separator, U+2029 (for which Cocoa provides the constant NSParagraphSeparatorCharacter ), and an unambiguous line separator, U+2028 (for which Cocoa provides the constant NSLineSeparatorCharacter ). Unicode定义了一个明确的段落分隔符, U+2029 (Cocoa为其提供常量NSParagraphSeparatorCharacter ),以及一个明确的行分隔符U+2028 (Cocoa为其提供常量NSLineSeparatorCharacter )。

In the Cocoa text system, the NSParagraphSeparatorCharacter is treated consistently as a paragraph break, and NSLineSeparatorCharacter is treated consistently as a line break that is not a paragraph break—that is, a line break within a paragraph. 在Cocoa文本系统中, NSParagraphSeparatorCharacter被一致地视为段落,并且NSLineSeparatorCharacter被一致地视为不是段落中断的换行符,即段落中的换行符。 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. 例如,POSIX级软件通常只识别\\n作为中断。 Some older Macintosh software recognizes only \\r , and some Windows software recognizes only \\r\\n . 一些较旧的Macintosh软件只承认\\r ,和一些Windows软件,只承认\\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 to NSParagraphSeparatorCharacter . Cocoa文字系统识别\\n\\r\\r\\n全部为分段符,相当于NSParagraphSeparatorCharacter When it inserts paragraph breaks, for example with insertNewline :, it uses \\n . 当它插入段落符号时,例如insertNewline :,它使用\\n Ordinarily NSLineSeparatorCharacter is used only for breaks that are specifically line breaks and not paragraph breaks, for example in insertLineBreak :, or for representing HTML <br> elements. 通常, NSLineSeparatorCharacter仅用于特定换行符而不是段落符的断点,例如在insertLineBreak :中,或用于表示HTML <br>元素。

If your breaks are specifically intended as line breaks and not paragraph breaks, then you should typically use NSLineSeparatorCharacter . 如果您的休息时间专门用作换行符而不是分段符,那么您通常应该使用NSLineSeparatorCharacter Otherwise, you may use \\n , \\r , or \\r\\n depending on what other software is likely to process your text. 否则,您可以使用\\n\\r \\n\\r\\n取决于其他软件可能处理您的文本。 The default choice for Cocoa is usually \\n . Cocoa的默认选择通常是\\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. Objective-c是c的超集,因此来自c的大部分内容也将在objective-c中起作用。

它同样。在目标c“\\ n”中用于换行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM