Please help me, I use Xcode 8.3(swift 3.1), the function trimmingCharacters
not work. My code as below:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if var searchStr = textField.text{
let _searchStr = searchStr.trimmingCharacters(in: .whitespaces)
print("After trimming:(_searchStr)")
}
}
The input in textfield is 409 hu?nh
and the print result is 409 hu?nh
not as expected: 409hu?nh .
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…