//Creation of Strings//in a variable string, a hollow string has meaning .Nsmutablestring *mstring =[[Nsmutablestring alloc]init]; NSLog (@"mstring:%@", mstring); //mutable strings cannot be used with string assignments in code areasNsmutablestring *mstring2 =@"Hello";//MString2 will degenerate into NSString .NSLog (@"mstring2:%@", mString2); //You can specify the space size of a string to create a stringNsmutablestring *mstring3 =[nsmutablestring stringwithcapacity: -]; NSLog (@"mstring3:%@", MString3); //variable string Add contentnsmutablestring *mstring4 = [[nsmutablestring alloc]initwithstring:@"Hello"]; [MString4 appendString:@" World"];//to MString4 StitchingNSLog (@"mstring4:%@", MString4); //you can add string content at the specified location[MString4 insertstring:@"123"Atindex:5]; NSLog (@"mstring4:%@", MString4); //Delete Contentnsmutablestring *mstring5 = [[nsmutablestring alloc]initwithstring:@"I am Learning objective-c language."]; //finds the string content, where it is located in the stringNsrange range = [MString5 rangeofstring:@"Learn"];//What you need to deleteNSLog (@"Range:loc:%lu Length:%lu", range.location,range.length); //delete the specified content in a mutable string[MString5 Deletecharactersinrange:range]; NSLog (@"mstring5:%@", MSTRING5); //Replace contentnsmutablestring *mstring6 = [[nsmutablestring alloc]initwithstring:@"helloworld!"]; [MString6 Replacecharactersinrange:nsmakerange (4,3) Withstring:@"1234"]; NSLog (@"mstring6:%@", MString6);
Nsmutablestring Common operations