NSMutableString -- variable string, nsmutablestring --
//// Main. m // OC04-task-05 // Created by keyzhang on 15-1-24. // Copyright (c) 2015 keyzhang. all rights reserved. // # import <Foundation/Foundation. h> int main (int argc, const char * argv []) {@ autoreleasepool {// insert code here... //// // NSMutableString -- variable string // NSMutableString inherited from NSString // initWithFormat: is the method of the parent class used NSMutableString * str1 = [[NSMutableString alloc] initWithFormat: @ "abc"]; NSLog (@ "str1 is % @", str1 ); // create an empty string NSMutableString * str2 = [NSMutableString string]; NSLog (@ "str2 is % @", str2); // insert a string, on the original basis, modify [str1 insertString: @ "hello world" atIndex: 0]; NSLog (@ "str1 is % @", str1 ); // Delete the string nsange range = {11, 3}; [str1 deleteCharactersInRange: range]; NSLog (@ "str1 is % @", str1); // append the string, append the string directly to [str1 appendString: @ "hehe"]; NSLog (@ "str1 is % @", str1); int index = 123456; [str1 appendFormat: @ "% d", index]; NSLog (@ "str1 is % @", str1); // specify a range and replace [str1 replaceCharactersInRange: NSMakeRange (0, 5) withString: @ "a"]; NSLog (@ "str1 is % @", str1); // note: you need to compare and learn the corresponding method of immutable string // The variable string append string method is modified based on your own, this method does not return a value // [str1 appendFormat: <# (NSString *),... #>]; // the immutable string append string method has a return value. The append string is returned. // [str1 stringByAppendingFormat: <# (NSString *),... #>]} return 0 ;}