swift3 String常用操作

  1. 去除首尾的空格
// 去除空格
var getName:String = textField.text!
getName = getName.trimmingCharacters(in: .whitespaces)
  1. 替换文字
// 替换文字
strNewMem = strNewMem.replacingOccurrences(of: "\n  \"\",", with: "")
strNewMem = strNewMem.replacingOccurrences(of: ",\n  \"\"", with: "")
  1. 字符串分割
let da = "a,b,c"
let arr = da.components(separatedBy: ",")
print(arr)

你可能感兴趣的:(swift3 String常用操作)