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

Re: substringToIndex problem


  • Subject: Re: substringToIndex problem
  • From: Greg Titus <email@hidden>
  • Date: Sat, 31 May 2003 11:51:03 -0700

On Saturday, May 31, 2003, at 11:38 AM, Peter Karlsson wrote:

Dear list!

Can someone please tell me why this does not work? All I want to do is: If the string begins with 'Loop' I want to set the string to Loop.

if ([theValue substringToIndex: 4] == @"Loop")
{
theValue = @"Loop";
}

Because you can't compare two NSStrings using "==". "==" performs a comparison of the pointer values, not a comparison of the contents.

You want:

if ([[theValue substringToIndex: 4] isEqualToString:@"Loop")

Except that it will be more efficient and easier to use the -hasPrefix: method instead:

if ([theValue hasPrefix:@"Loop"])

Hope this helps,
- Greg
_______________________________________________
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: 
 >substringToIndex problem (From: "Peter Karlsson" <email@hidden>)

  • Prev by Date: Re: substringToIndex problem
  • Next by Date: Re: substringToIndex problem
  • Previous by thread: Re: substringToIndex problem
  • Next by thread: Re: substringToIndex problem
  • Index(es):
    • Date
    • Thread