Is there a short way to say "entire string" rather than typing out:
NSMakeRange(0, myString.length)]
It seems silly that the longest part of this kind of code is the least important (because I usually want to search/replace within entire string)…
[myString replaceOccurrencesOfString:@"replace_me" withString:replacementString options:NSCaseInsensitiveSearch range:NSMakeRange(0, myString.length)];
Function? Category method?
- (NSRange)fullRange { return (NSRange){0, [self length]}; }
[myString replaceOccurrencesOfString:@"replace_me" withString:replacementString options:NSCaseInsensitiveSearch range:[myString fullRange]];
Swift 4+, useful for NSRegularExpression
and NSAttributedString
extension String { var nsRange : NSRange { return NSRange(self.startIndex..., in: self) } func range(from nsRange: NSRange) -> Range<String.Index>? { return Range(nsRange, in: self) } }
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