NSString Method’s in Objective-C


Q.33 Explain any 15 methods of NSString.? Ans:-

  • NSString is a predifine class avilable in Foundation Framework.
  • 1)stringWithString – By using this we can create a string object with another string content.(class method).
  • 2)Length – By Using this method, we can find length of string.
  • 3)stringByAppendString – By using this method, we can append a string to another string String appending always takes place at the end of the current string only.
  • 4)stringWithFormat – It is class method which is used to create a string object in customized format.(user define format string data).
  • stringWithFormat
  • 5)isEqualToString – This method is used to compare both string are same or not.This method return boolean value i.e YES or NO. this method use to access another string there same string character avilable.Match the one string to another string then go for isEqualToString.
  • 6)stringByAppendingFormat – By using this method, we can append customized string format data to existing string.
  • 7)lowerCaseString. – This method will convert current string content in lower case format (chractrer’s).
  • 8)upperCaseString – This method will convert current string data into lower case.
  • 9)stringWithUTF8String – It is a class method which is used to create NSString object into ‘C’ type string.
  • 10)compare – By using this method, we can compare 2 string.Compare method returns NSComparisonResult value.NSComparisonResult value can be NSOrderedAscending or NSOrderedSame or NSOrderedDescending.
  • 11)subStringToIndex – By using this method we can extract the substring upto give location.
  • 12)subStringFromIndex – By using this method we can extract the substring from given location to end of the string.
  • 13)substringWithRange – By using this method we can extract the substring in specific range.When we are using this method we require to pass NSRange value. i.e location , length.
  • 14)rangeOfString – This method will return substring range in the form of NSRange data i.e location and length.
  • 15)UTF8String  – This method is used to convert unicode string to C type string.(NSString to char*)

Kalavati Technologies Pvt Ltd