I have string as 2/42
. Here 2 & 42 is dynamic.Now I want to set /42
as superscript of string. I am not able to find out the range of /42
. please tell me how do i find out the range in swift?
Mutable string of attributed string has functionality to find of range of specific string.
Try this and see (Swift 4):
let stringValue = "2/42"
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: stringValue)
let range: NSRange = attributedString.mutableString.range(of: "/42", options: .caseInsensitive)
print("range - \(range)")
Result:
range - {1, 3}
Ref Snapshot:
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