Swift - Remove " character from string
Solution 1:
Swift uses backslash to escape double quotes. Here is the list of escaped special characters in Swift:
\0
(null character)\\
(backslash)\t
(horizontal tab)\n
(line feed)\r
(carriage return)\"
(double quote)\'
(single quote)
This should work:
text2 = text2.replacingOccurrences(of: "\\", with: "", options: NSString.CompareOptions.literal, range: nil)
Solution 2:
Swift 3 and Swift 4:
text2 = text2.textureName.replacingOccurrences(of: "\"", with: "", options: NSString.CompareOptions.literal, range:nil)
Latest documents updated to Swift 3.0.1 have:
- Null Character (
\0
)- Backslash (
\\
)- Horizontal Tab (
\t
)- Line Feed (
\n
)- Carriage Return (
\r
)- Double Quote (
\"
)- Single Quote (
\'
)- Unicode scalar (
\u{n}
), where n is between one and eight hexadecimal digits
If you need more details you can take a look to the official docs here