Swift Special Characters in String Literals
Swift Special Characters:
Normally, the characters in a string are displayed exactly as they appear in the double quotes. However, the paired characters \ and n, repeated three times in the statement, do not appear on the screen. The backslash (\) is an escape character, which has special meaning in a String literal – \n. It represents the line-feed special character. When the screen’s output cursor moves to the beginning of the next line in the standard output.
Special Character | Description |
---|---|
\n | Line feed (It is often called newline). Position the screen cursor at the beginning of the next line. |
\t | Horizontal tab. Move the screen cursor to the next tab stop. |
\\ | Backslash. It is used to print a backslash character. |
\r | Carriage return. Position the screen cursor at the beginning of the current line, do not advance to the next line. |
\" | Double quote. It is used to insert a double-quote character. |
\' | Single quote. It is used to insert a single-quote character. |
\0 | Null Character. |
\u{n} | A Unicode character - n is between one and eight hexadecimal digits. |