• 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: strpos-type method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strpos-type method


  • Subject: Re: strpos-type method
  • From: James Bucanek <email@hidden>
  • Date: Thu, 20 Jul 2006 16:46:45 -0700

Drarok Ithaqua wrote on Thursday, July 20, 2006:

>I've looked around for a while, and found some posts on CocoaDev, but
>nothing seems simple.
>
>I'm looking for basic string searching functionality, like PHP's
>strpos() [http://uk.php.net/strpos].
>
>Or rather, I want to know if a string is contained inside another
>string. if strpos() returns > -1 (or !== FALSE in PHP)
>then the string is at the returned position.
>
>But all I could find was NSString Categories that did a very long
>winded method, and had a comment with the following code
>(Adapted for my app, natch)
>
>   if (([[incomingText componentsSeparatedByString:@"(Quit)"] count] -
>1) > 0) {
>       // It's in the string
>   };

All I can say is "yikes!

Try

    if ([incomingText rangeOfString:@"(Quit)"].location!=NSNotFound)
        {
        // incomingText contains "(Quit)"
        }
--
James Bucanek
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >strpos-type method (From: Drarok Ithaqua <email@hidden>)

  • Prev by Date: Re: strpos-type method
  • Next by Date: Re: strpos-type method
  • Previous by thread: Re: strpos-type method
  • Next by thread: changing a single row in NSOutlineView to different control
  • Index(es):
    • Date
    • Thread