Search code examples
objective-cnsstringescapingstring-literals

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.


Solution

  • There's no equivalent to the triple-quote; string literals must always use escapes for special characters.

    Perhaps the best thing to do would be to put your HTML into a file separate from your source, then create the string using -[NSString initWithContentsOfFile:encoding:error:] (or the related initWithContentsOfURL:...).