Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if NSString does not equal function?

I have searched all over the place for this, including apple's docs on NSString (maybe I didn't see?) but I am trying to find a method in xCode for checking wether a NSString does not equal to something. Much like

if (myNSSting = @"text" {...

except specifically I want to check if it does not equal to 'text'.

like image 905
Alex Avatar asked Mar 13 '13 02:03

Alex


People also ask

What does NSString mean?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior. iOS 2.0+ iPadOS 2.0+ macOS 10.0+ Mac Catalyst 13.0+ tvOS 9.0+ watchOS 2.0+

Do I need to release NSString?

If you create an object using a method that begins with init, new, copy, or mutableCopy, then you own that object and are responsible for releasing it (or autoreleasing it) when you're done with it. If you create an object using any other method, that object is autoreleased, and you don't need to release it.

How do I append to NSString?

Once a string has been initialized using NSString, the only way to append text to the string is to create a new NSString object. While doing so, you can append string constants, NSString objects, and other values.


2 Answers

 if(![myNSString isEqualToString:@"text"])
like image 143
Shashank Avatar answered Sep 19 '22 02:09

Shashank


For case insensitive compare we can handle by:

 if( [@"Some String" caseInsensitiveCompare:@"some string"] == NSOrderedSame ) {
      // strings are equal except for possibly case
    }
like image 27
Suhaiyl Avatar answered Sep 19 '22 02:09

Suhaiyl