nsstring *str1 = @ "This is a example.";
nsmutablestring *mstr = [[Nsmutablestring alloc] init];//create variable string
nsrange substr;//substring range
MSTR = [nsmutablestring stringwithstring:str1];
//Insert character
[MSTR insertstring:@ "very easy" atindex:10];
//Delete some characters
[Mstr Deletecharactersinrange:nsmakerange (10,5)];
//Find and delete
substr = [MSTR rangeofstring:@ "Easy"];
if (substr.location! = nsnotfound) {
[Mstr Deletecharactersinrange:substr];
}
//Reset String
[MSTR setstring:@ "This is A string A"];
//Replace string
[Mstr Replacecharactersinrange:nsmakerange (1) withstring:@ "BBB"];
//Find the first one and replace
nsstring *search = @ "This is";
nsstring *replace = @ "An example of";
substr = [MSTR Rangeofstring:search];
if (substr.location! = nsnotfound) {
[MSTR replacecharactersinrange:substr withstring:replace];
}
//Find all matches, and replace
search = @ "a";
replace = @ "X";
substr = [MSTR Rangeofstring:search];
While (substr.location! = nsnotfound) {
[MSTR Replacecharactersinrange:substr withstring:replace];
substr = [MSTR Rangeofstring:search];
}
Remove spaces
[String stringbyreplacingoccurrencesofstring:@ "" withstring:@ ""]
Insertion and deletion of iOS strings find and replace, remove spaces