多行声明一个 NSString
有没有办法在多行中声明 NSString
?我想编写 HTML 代码并将其存储到 NSString
中,并且多行代码将更具可读性。我想做这样的事情:
NSString *html = @"\<html\>"
+ @"\<head\>"
+ @"\<title\>The Title of the web\</title\>"
+ @"\</head\>"
+ @"\<body\>"
[...]
Is there any way to declare a NSString
in multiple lines? I want to write HTML code and store it into a NSString
, and in multiple lines de code will be more readable. I want to do something like this:
NSString *html = @"\<html\>"
+ @"\<head\>"
+ @"\<title\>The Title of the web\</title\>"
+ @"\</head\>"
+ @"\<body\>"
[...]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个例子:
This is an example:
我知道这是 Objective-C 的问题,但用 Swift 就很容易了:
I know it's Objective-C question but it's pretty easy with Swift:
并注意每行开头的制表符/空格 - 在这种情况下它们确实很重要。
And beware of tabs/spaces in the beginning of each line - they do count in this case.
创建一个具有多行的 NSString 来模拟从多行文本文件读取的 NSString。
最后一行的 \n 由您决定。
Create an NSString with multiple lines to mimic a NSString read from a multi-line text file.
A \n on the last line is up to you.