• 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: String Contains String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String Contains String


  • Subject: Re: String Contains String
  • From: Daniel Jalkut <email@hidden>
  • Date: Thu, 31 May 2007 11:14:35 -0400

On May 31, 2007, at 11:02 AM, Andrew James wrote:

Hi,

Is there a way to check if a string contains a string? what i am attempting to do is get the results of pmset -g and see if it contains hibernatefile

Unless of course there is a simple way to read whats in PMSet, i know it is possible to use grep in the NSTask however i also want to check for a second setting which would double the code etc.

I think the easiest way is to use rangeOfString:

NSRange foundRange = [targetString rangeOfString:searchTermString];
BOOL containsString = (foundRange.location != NSNotFound);

Of course if you want to do more than just see if the string is in there, the information you need is all contained in that range struct.

Daniel

--------------
Daniel Jalkut
http://www.red-sweater.com/blog/


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >String Contains String (From: Andrew James <email@hidden>)

  • Prev by Date: Re: String Contains String
  • Next by Date: Re: String Contains String
  • Previous by thread: Re: String Contains String
  • Next by thread: Re: String Contains String
  • Index(es):
    • Date
    • Thread