OC: Some Usage of variable string NSMutableString, ocnsmutablestring
NSString is an immutable string, so the method is not to modify the original string, but to create a copy of the original string, and then modify the copy content.
NSMutableString is a subclass of NSString and all its methods can be used.
1. NSMutableString provides the method for appending strings.
You can use appendString or appendFormat to operate a variable string:
-(Void) appendString: (NSString *) string;
-(Void) appendFormat: (NSString *) string;
AppendString accepts the string parameter, and then copies it to the end of the receiving object.
AppendFormat is similar. It attaches the formatted string to the end of the accepted object, rather than creating a new object.
2. Insert a string
NSMutableString * str = [[NSMutableString alloc] initWithFormat: @ "abc"];
[Str insertString: @ "xyz" atIndex: 2];
3. Replace string
[Str replaceCharactersInRange: NSMakeRange (123) withString: @ ""];
4. delete a string
[String19 deleteCharactersInRange: NSMakeRange (0, 3)];