I retrieved some strings from AddressBook.framework
's ABRecordCopyValue
method by casting the returned value of takeRetainedValue()
as a String
object.
let unmanagedFirstNameProperty = ABRecordCopyValue(person, kABPersonFirstNameProperty)
if unmanagedFirstNameProperty != nil {
contactFirstName = unmanagedFirstNameProperty!.takeRetainedValue() as? String
}
let formattedName:String = contactFirstName.replaceOccurrences(of: " ", with: "")
print(formattedName)
I want to get rid of the spaces inside this String
object by calling replaceOccurrences(of:with:)
method, but that doesn't work (the spaces are still there after I call this method) and I was told by the Apple Framework Reference that this is usually because of the string encoding, containing "non-break spaces" which I've heard a lot about, but I have no idea how to make a "non-break space" into a normal space. Is this even possible? If so, what would be the best approach to make the characters inside a String
compatible with the replaceOccurrences(of:with:)
method?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…