I have AttributedString with emoji like this "🤣🤣🤣 @Mervin tester 🤣🤣🤣"
Now I need to find a range of Mervin in this attributed String.
let attributedString = NSMutableAttributedString(string: "🤣🤣🤣 @Mervin tester 🤣🤣🤣")
let range = // range for "Mervin" in above String.
Thank you.
This extension should help you.
extension NSAttributedString {
func rangeOf(string: String) -> Range<String.Index>? {
return self.string.range(of: string)
}
}
Usage:
attributedString.rangeOf(string: "Mervin")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With