我正在尝试从字符串中删除空格和一些字符,请查看我的下面的代码。
// giving phoneString = +39 333 3333333
var phoneString = ABMultiValueCopyValueAtIndex(phone, indexPhone).takeRetainedValue() as! String
// Remove spaces from string
phoneString = phoneString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
// Remove +39 if exist
if phoneString.rangeOfString("+39") != nil{
phoneString = phoneString.stringByReplacingOccurrencesOfString("\0", withString: "+39", options: NSStringCompareOptions.LiteralSearch, range: nil)
}
print(phoneString) // output +39 333 3333333
看起来我的字符串没有受到任何更改的影响,这是为什么?
编辑@VS
编辑2:
我尝试将我的字符串转换为utf8,查看结果:
43 51 57 194 160 51 51 51 194 160 51 51 51 51 51 51 51
其中:
43 = +
51 = 3
57 = 9
160 = space
194 = wtf?!? is this?