Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to include a quotation mark as part of an nsstring?

I have a label that displays inches. I would like to display the number with the inch symbol (") or quotation mark. Can I do this with an nsstring? Thanks!

like image 668
Jonah Avatar asked Dec 20 '09 04:12

Jonah


People also ask

How do you include a quote in regex?

Try putting a backslash ( \ ) followed by " .

How do you add quotation marks in markdown?

The correct way to write quotes in Markdown is to just write quotes literally, i.e., use " " . They will be converted to the correct LaTeX code (i.e., `` '' ) when Markdown is converted to LaTeX (via Pandoc). The same thing applies to single quotes.

How do I put a quote in a string in C++?

To place quotation marks in a string in your code In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark.

How do you put quotation marks in a string Swift?

To include quotes inside a string in Swift, escape the quote symbol with backslash character, i.e., place a backslash character before the double quote inside the string.


3 Answers

Sure, you just need to escape the quotation mark.

NSString *someString = @"This is a quotation mark: \""; NSLog(@"%@", someString ); 

Output:

This is a quotation mark: " 
like image 95
3 revs, 3 users 88% Avatar answered Oct 13 '22 05:10

3 revs, 3 users 88%


You can use Double Quote Escape Sequence here. You need to escape it using a backslash :

NSString *str = @"Hello \"World\"";
NSLog(@"Output : %@",str);

Output : Hello "World"

There are some other Escape Sequences also. Take a look at it :

\b    Backspace
\f    Form Feed
\n    Newline
\t    Horizontal Tab
\v    Vertical Tab
\\    Backslash
\’    Single Quote
\”    Double Quote
\?    Question Mark
like image 44
Bhavin Avatar answered Oct 13 '22 03:10

Bhavin


As use of back slash \" has already mentioned so I am answering different. You can use ASCII Code too.

ASCII Code of " (double quote) is 34.

 NSString *str = [NSString stringWithFormat:@"%cThis is a quotation mark: %c", 34, 34];
 NSLog(@"%@", str);

And Output is: "This is a quotation mark: "

Swift 4.0 Version

let str = String(format: "%cThis is a quotation mark: %c", 34, 34)
print(str)
like image 41
TheTiger Avatar answered Oct 13 '22 04:10

TheTiger