• 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: Problems with isEqualToString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with isEqualToString


  • Subject: Re: Problems with isEqualToString
  • From: Andy Lee <email@hidden>
  • Date: Sat, 23 Mar 2002 14:43:37 -0500

At 11:22 AM -0800 3/23/02, Ben Mackin wrote:
resultString = [[NSString alloc]
initWithContentsOfFile:@"/tmp/errorCode"];
[[NSFileManager alloc] removeFileAtPath:@"/tmp/errorCode" handler:nil];
NSLog(@"my result code");
NSLog(resultString); //Note that right here I see it is success
if([resultString isEqualToString:@"success"]==YES)
{

When you load resultString from the text file it has a newline at the end of it. That is why it does not match the string @"success". You should either chop the newline off or compare resultString to @"success\n".

Because of subtleties like this, when I print a string value for debugging purposes, I surround it with a delimiter (usually square brackets, out of habit). For example:

NSLog(@"my result code: [%@]", resultString);

This would have shown you something like...

my result code: [success
]

...and you would have seen there was a newline before the closing square bracket.

--Andy
_______________________________________________
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: 
 >Problems with isEqualToString (From: Ben Mackin <email@hidden>)

  • Prev by Date: Re: Rép : Cocoa's Popularity
  • Next by Date: Re: Problems with isEqualToString
  • Previous by thread: Re: Problems with isEqualToString
  • Next by thread: Re: Problems with isEqualToString
  • Index(es):
    • Date
    • Thread