I\'ve got a problem with removing whitespaces at the beginning and end of string. For e.g. I\'ve got a string like:
\\r\\n\\t- Someone will come here?\\n- I d
Your string contains not only whitespace but also new line characters.
Use stringByTrimmingCharactersInSet
with whitespaceAndNewlineCharacterSet
.
let string = "\r\n\t- Someone will come here?\n- I don't know for sure...\r\n\r\n"
let trimmedString = string.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
In Swift 3 it's more cleaned up:
let trimmedString = string.trimmingCharacters(in: .whitespacesAndNewlines)