Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raw strings like Python's in Objective-C

Does Objective-C have raw strings like Python's?

Clarification: a raw string doesn't interpret escape sequences like \n: both the slash and the "n" are separate characters in the string. From the linked Python tutorial:

>>> print 'C:\some\name'  # here \n means newline!
C:\some
ame
>>> print r'C:\some\name'  # note the r before the quote
C:\some\name
like image 555
Casebash Avatar asked Dec 03 '22 06:12

Casebash


2 Answers

Objective-C is a superset of C. So, the answer is yes. You can write

char* string="hello world";

anywhere. You can then turn it into an NSString later by

NSString* nsstring=[NSString stringWithUTF8String:string];
like image 195
Yuji Avatar answered Dec 27 '22 03:12

Yuji


From your link explaining what you mean by "raw string", the answer is: there is no built in method for what you are asking.

However, you can replace occurrences of one string with another string, so you can replace @"\n" with @"\\n", for example. That should get you close to what you're seeking.

like image 34
Dave DeLong Avatar answered Dec 27 '22 03:12

Dave DeLong