1.去掉字符串中全部空格
//方法1
let str = " ee fjdska ljkj"
let string = str.replacingOccurrences(of: " ", with: "")
//方法2
let string = st.components(separatedBy: " ").joined(separator: "")
2.去掉两头的空格
let str = " ee fjdska ljkj"
let strings = str.trimmingCharacters(in: CharacterSet.whitespaces)//去掉两头的空格
3.去掉通讯录中获取的电话号码的空格
let textStr = phoneNumber.value.stringValue.components(separatedBy: CharacterSet.whitespaces).joined(separator: "")
网友评论