Re: replaceFirstOccurenceOf?
Re: replaceFirstOccurenceOf?
- Subject: Re: replaceFirstOccurenceOf?
- From: James Quick <email@hidden>
- Date: Fri, 1 Aug 2003 13:24:44 -0400
On Friday, August 1, 2003, at 11:36 AM, Michael Hanna wrote:
I've been looking through the classes for something that will let me
replace the first occurence of a substring in an NSMutableString.
NSMutableString:replaceOccurrencesOfString:
is close but I don't want to replace all, just the FIRST occurence.
Any suggestions?
Michael
One way might be,
NSRange whereFound = [myString rangeOfString: substring];
if (whereFound.location != NSNotFound) {
[myString replaceCharactersInRange: whereFound withString:
replacementString]
}
If performance is critical, or to search in a different direction, or
choose CaseInsensitve vs.
Literal comparisons, go straght to the most primitive method for
finding the substring.
NSRange wholeRange = NSMakeRange(0, [myString length];
NSRange whereFound = [myString rangeOfString: substring
NSCaseInsensitiveSearch range: wholeRange];
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.