Is there a way to have double-quotation marks in strings in Objective C without escaping them?
In PHP you can wrap a string in single quotation marks, in which case you do not have to escape anything in the string.
Is there a way to have double-quotation marks in strings in Objective C without escaping them?
In PHP you can wrap a string in single quotation marks, in which case you do not have to escape anything in the string.
The only chance is to compile your source as Objective-C++ file
(file suffix ".mm"). Then the C++ raw string literals are also accepted when defining an NSString
,
for example
NSString *str = @R"(Hello"World\n)";
has the 13 characters
H e l l o " W o r l d \ n
But that feature is only available in (Objective-)C++ source files, not in (Objective-)C.
Unfortunately, there is no way (that I know of) to have an unescaped quotation mark inside a string in Objective-C. You can get a quotation mark using unicode or some other trick, but I believe that you want a less ugly way to write a quotation inside a string, not an even uglier one :)
P.S. Just for fun I've just tried to use a unicode escape sequence (@"\u0022"
), and it turned out it is forbidden.
Curly quotes don't require escaping, and generally look better for messages presented to the end user:
NSString *str = @"Hello, “World”!";