discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Searching NSString


From: Sašo Kiselkov
Subject: Re: Searching NSString
Date: Tue, 01 May 2007 21:55:24 +0200
User-agent: Thunderbird 1.5.0.10 (X11/20070306)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Adam Fedor wrote:
> 
> On May 1, 2007, at 11:38 AM, Sašo Kiselkov wrote:
> 
>> BOOL ContainsString (NSString *string, NSString *keyword)
>> {
>>   return [string rangeOfString: keyword].location != NSNotFound;
>> }
> 
> Slightly better:
> 
> BOOL ContainsString (NSString *string, NSString *keyword)
> {
>   return (string != NULL) && ([string rangeOfString: keyword].location
> != NSNotFound);
> }
> 
> as OSs like Solaris will crash if you try to treat a NULL pointer as a
> structure.
> 
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> http://lists.gnu.org/mailman/listinfo/discuss-gnustep
> 

I actually tend to use the following approach, which I consider the nicest:

@implementation NSString (Additions)
- - (BOOL) containsString: (NSString *) otherString
{
  return [self rangeOfString: otherString].location != NSNotFound;
}
@end

- --
Saso
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGN5srakxhuWWzY78RAyOZAJ9IuWYY9LnrvzclSyo+/HZTrwTUQgCglxyI
ZuTbw4Kgo6B7qSOdXhGvX+s=
=VD9N
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]