• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: replaceFirstOccurenceOf?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
References: 
 >replaceFirstOccurenceOf? (From: Michael Hanna <email@hidden>)

  • Prev by Date: Re: Fast User Switching in Panther...
  • Next by Date: Re: Learning Mac programming
  • Previous by thread: Re: replaceFirstOccurenceOf?
  • Next by thread: Re: Fw: Dialog disposing problem in Mac OS Ver 10.2.6
  • Index(es):
    • Date
    • Thread