#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
Nsmutablestring *mustr1=[[nsmutablestring Alloc]init];
Nsmutablestring *mustr2=[nsmutablestring stringwithformat:@ "Hello"];
Nsmutablestring *mustr3=[[nsmutablestring Alloc]init];
NSString *[email protected] "welcom to OC";
nsmutablestring *[email protected] "welcom to OC"; This is wrong--you cannot assign a string constant directly to Nsmutablestring
Assign value
Mustr1=[nsmutablestring STRINGWITHSTRING:STR];
NSLog (@ "mustr1=%@", MUSTR1);
Replace string
Nsrange rang2=[mustr1 rangeofstring:@ "OC"];
[Mustr1 replacecharactersinrange:rang2 withstring:@ "IOS"];
NSLog (@ "mustr1=%@", MUSTR1);
Insert
[Mustr1 insertstring:@ "student" atindex:6]; Specify position 6 Insert string
[Mustr2 appendstring:@ "teacher!"]; Insert string at end
[Mustr3 appendformat:@ "hey!%@", str]; Formatting the insertion string
NSLog (@ "mustr1=%@", MUSTR1);
NSLog (@ "mustr2=%@", MUSTR2);
NSLog (@ "mustr3=%@", MUSTR3);
Specify location Delete
[Mustr1 Deletecharactersinrange:nsmakerange (7, 8)]; Remove 8 characters at position 7
NSLog (@ "mustr1=%@", MUSTR1);
Find Delete
Nsrange rang1=[mustr2 rangeofstring:@ "Teacher"];
if (rang1.location!=nsnotfound) {
[Mustr2 deletecharactersinrange:rang1];
}
NSLog (@ "mustr2=%@", MUSTR2);
Re-assign Value
[Mustr2 SETSTRING:STR];
NSLog (@ "mustr2=%@", MUSTR2);
}
return 0;
}
Replace the string (replace the string content you want to replace directly)/delete (delete the specified location/delete the location you want to delete)/