(Swift) how to print "\" character in a string?

Rahul Sonvane picture Rahul Sonvane · May 11, 2015 · Viewed 42.8k times · Source

I have tried to print it but it just by passes because it's an escaped character. e.g output should be as follows.

\correct

Answer

C-JARP picture C-JARP · May 11, 2015

For that and also future reference:

\0 – Null character (that is a zero after the slash)
\\ – Backslash itself.  Since the backslash is used to escape other characters, it needs a special escape to actually print itself.
\t  – Horizontal tab
\n – Line Feed
\r  – Carriage Return
\”  – Double quote.  Since the quotes denote a String literal, this is necessary if you actually want to print one.
\’  – Single Quote.  Similar reason to above.