Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String literals without having to escape special characters?

Is there a string literal form in Objective-c that does not require escaping special characters? In other words, I'm looking for an equivalent to the Python triple quote.

I'm trying to put some HTML into an NSString, and would like to avoid having to escape the quotes from all the HTML attributes.

like image 627
pepsi Avatar asked Jan 26 '12 20:01

pepsi


1 Answers

In C++11 you can do this. See my answer to a similar question.

For this you require in your case Objective-C++11. It should work though in gcc.

const char * html = R"HTML(
<HTML>
 <HEAD>
   <TITLE> [Python-Dev] Triple-quoted strings and indentation
   </TITLE>
 </HEAD>
 <BODY BGCOLOR="#ffffff">
  blah blah blah
 </BODY>
</HTML>
)HTML";

int
main()
{
}

g++ -std=c++0x -o raw_string raw_string.mm at least compiles.

like image 125
emsr Avatar answered Sep 18 '22 12:09

emsr