Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare a NSString in multiple lines

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\>"
[...]
like image 276
Jimmy Avatar asked Oct 03 '11 10:10

Jimmy


People also ask

How do you write a multiline string in C++?

Using Backslash If we place a backslash at the end of each line, the compiler removes the new-line and preceding backslash character. This forms the multiline string.

How do you define a long string?

Long strings can be written in multiple lines by using two double quotes ( “ “ ) to break the string at any point in the middle.

How do you define multiline string in JS?

There are three ways to create a multiline string in JavaScript. We can use the concatenation operator, a new line character (\n), and template literals. Template literals were introduced in ES6. They also let you add the contents of a variable into a string.


1 Answers

This is an example:

NSString *html = [NSString stringWithFormat:@"<html> \n"
                          "<head> \n"
                          "<style type=\"text/css\"> \n"
                          "body {font-family: \"%@\"; font-size: %dpx;}\n"
                          "img {max-width: 300px; width: auto; height: auto;}\n"
                          "</style> \n"
                          "</head> \n"
                          "<body><h1>%@</h1>%@</body> \n"
                          "</html>", @"helvetica", 16, [item objectForKey:@"title"], [item objectForKey:@"content:encoded"]];
like image 147
Raptor Avatar answered Sep 28 '22 05:09

Raptor