# Import <Foundation/nsstring. h>
# Import <Foundation/nfutoreleasepool. h>
Int main (INT argc, const char * argv []) {
NSAID utoreleasepool * Pool = [[NSAID utoreleasepool alloc] init];
Nsstring * str1 = @ "this is a example .";
Nsmutablestring * mstr = [[nsmutablestring alloc] init];
Nsange substr;
// Create a variable string
Mstr = [nsmutablestring stringwithstring: str1];
Nslog (@ "% @", mstr );
// Insert characters
[Mstr insertstring: @ "very easy" atindex: 10];
Nslog (@ "% @", mstr );
// Delete some characters
[Mstr deletecharactersinrange: nsmakerange (10, 5)];
Nslog (@ "% @", mstr );
// Search for and delete
Substr = [mstr rangeofstring: @ "easy"];
If (substr. location! = Nsnotfound ){
[Mstr deletecharactersinrange: substr];
Nslog (@ "% @", mstr );
}
// Reset the string
[Mstr setstring: @ "this is string a"];
// Replace the string
[Mstr replacecharactersinrange: nsmakerange (15, 1) withstring: @ "BBB"];
Nslog (@ "% @", mstr );
// Search for and replace the first one
Nsstring * search = @ "this is ";
Nsstring * replace = @ "an example ";
Substr = [mstr rangeofstring: Search];
If (substr. location! = Nsnotfound ){
[Mstr replacecharactersinrange: substr withstring: replace];
Nslog (@ "% @", mstr );
}
// Search for all matched items and replace them
Search = @ "";
Replace = @ "X ";
Substr = [mstr rangeofstring: Search];
While (substr. location! = Nsnotfound ){
[Mstr replacecharactersinrange: substr withstring: replace];
Substr = [mstr rangeofstring: Search];
}
Nslog (@ "% @", mstr );
[Pool drain];
Return 0;
}