Common NSMutableString operations,
// Create a string // empty strings in the variable string make sense NSMutableString * mString = [[NSMutableString alloc] init]; NSLog (@ "mString: % @", mString ); // variable strings cannot be assigned with strings in the code area. NSMutableString * mString2 = @ "Hello"; // mString2 will be degraded to NSString NSLog (@ "mString2: % @", mString2); // you can specify the space size of the string to create the string NSMutableString * mString3 = [NSMutableString stringWithCapacity: 30]; NSLog (@ "mString3: % @", mString3 ); // variable string add content NSMutableString * mString4 = [NSMut AbleString alloc] initWithString: @ "Hello"]; [mString4 appendString: @ "World"]; // concatenates NSLog (@ "mString4: % @", mString4) to mString4 ); // you can add the string content [mString4 insertString: @ "123" atIndex: 5]; NSLog (@ "mString4: % @", mString4) at the specified position ); // Delete content NSMutableString * mString5 = [[NSMutableString alloc] initWithString: @ "I am learning Objective-C language. "]; // find the content of the string. the position in the string is nsange range = [mString5 rangeOfString: @" learn "]; // NSLog (@ "range: loc: % lu length: % lu", range. location, range. length); // Delete the content specified in the variable string [mString5 deleteCharactersInRange: range]; NSLog (@ "mString5: % @", mString5 ); // replace content NSMutableString * mString6 = [[NSMutableString alloc] initWithString: @ "HelloWorld! "]; [MString6 replaceCharactersInRange: NSMakeRange (4, 3) withString: @" 1234 "]; NSLog (@" mString6: % @ ", mString6 );