General Nuisance
General Nuisance

Reputation: 211

escape characters in Swift

I specifically am wondering how you could escape a newline in Swift, but generic escape characters would be great too.

In Python you can do this:

print("Dear grandma, \nHow are you?")

How can you do this in Swift?

Upvotes: 2

Views: 9248

Answers (2)

Samaga
Samaga

Reputation: 98

Here is an example replacing a unicode character in a string with a comma (to give you a sense of using escaped unicodes).

address = address.stringByReplacingOccurrencesOfString("\u{0000200e}", withString: ",", options: nil, range: nil)

Upvotes: 1

gregheo
gregheo

Reputation: 4270

Newlines as \n work in Swift string literals too.

Check out the docs: Special Unicode Characters in String Literals

Upvotes: 2

Related Questions