Re: substringToIndex problem
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.