Home / iPhone

Exploring the Foundation Framework in iPhone - NSstring class

Rating: 4.0Blog-star
Views: 1977
by Ravindra Savaram
Last modified: August 10th 2020

NS string class:-

The NSString class and its mutable subclass, NSMutableString, provide an extensive set of APIS for working with strings, including methods for comparing, searching, and modifying strings. NSString objects are used extensively throughout Foundation and other Cocoa frameworks, serving as the basis for all textual and linguistic functionality on the platform. (To know further class types, refer to Exploring The Foundation Framework).

NSString is “toll-free bridged” with its Core Foundation counterpart, CFStringRef.

Looking for IOS/Iphone Development Training? Mindmahix is the best training institue in UK, US and many other countries.


        NSString * str =  @  “hello”;
    Str  = [NSString     StringwithString :  @  “hello”];
    NSLog (@ “the string  is @”,   str);


Int  x  =  23;
Float  y  =  25;
Str  = [NSString    String with Format:  @  “%d++%0.of “’,x, y];
NSLog(@ “str is   %@”, str);

//Conversion string to normal data type:

NSString *str3 =[NSString StringwithString   : @ “9989645323];
Int  number  =  [str3 in value];
NSLog (@  “number is %d”, number”);

//length of an string:

Int length   =[Str length];

//Lower case and upper case:

NSString *uppercase   =[Str   upperCaseString];
Ns string  *lowercase  =  [Str  lowerCase string];

//string comparison:

If ([str is equal to string :str3])
   Ns log (@  “strings are equal”);
Ns log (@ “the string are not equal”);


  // substring
// hello world
// 012345678910

--> // substrings
  NSString *sub string    =   [Str SubStringFromIndex:1];
  NSString * to string =  [Str .SubStringToIndex  :5];
Ns log (@    “the SubString is %@;   SubString);
Ns log (@ “the to String is %@;    to String );

// String  Separation :

 NSString   *  str4   =  @”23-4-2011”;
  NSArray    *  a array=[str4 Component separated by string :@  “-“];
  NSLog (@  “a Array  is %@”,  a array);

// String Appending:

NSMutableString *mutStr =  [NS Mutable string StringwithString  : @      “Hai”];
    [  mutStr  appendString :@  “how r you”];
  Ns log (@   “  the mut Str after appending is %@;  mut Str);
// String   replacing
// hi how r you
  Int no of Replacing  =   [MutStr replaceOccurrencesOfString:  @  “r” 
                                            With  String  :@  “are”  options: nil range
                                              :  NSMakeRange (0,[MutStr length])];
Ns log (@    “mutStr after replacing  is %@;  mutStr);

Drawing the string in a Rect:

[mutStr   drawInRect :   CG RectMake (0,0,100,40)with font:16]


Frequently Asked iPhone Interview Questions & Answers


About Author

NameRavindra Savaram
Author Bio


Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.