/* 1. The variable string @ "When I am young, I loved a girl in neighbor class." , extracted from Young to girl. Replace with @ "a teacher, I rather to teach student". */#import <foundation/foundation.h>int main (int argc, const char * argv[]) {@autoreleasepool {/* square Law One *///nsmutablestring * str = @ "When I am young, I loved a girl in neighbor class."; /* nsmutablestring * str1 = [[nsmutablestring alloc]initwithstring:@] When I am young, I loved a girl in neighbor C Lass. "]; [Str1 Replacecharactersinrange:nsmakerange (one, up) withstring:@ "a teacher, I rather to teach student"]; NSLog (@ "%@", str1); *//** Method Two first remove and insert */* nsmutablestring * str1 = [[nsmutablestring alloc]initwithstring:@] Whe n I was young, I loved a girl in neighbor class. "]; [Str1 Deletecharactersinrange:nsmakerange (11,22)]; NSLog (@ "%@", str1); [Str1 insertstring:@ "a teacher, I rather to teach student" atindex:11]; NSLog (@ "%@", str1); */* Method Three */* nsmutablestring * str1 = [[nsmutablestring alloc]initwithstring:@] when I am you Ng, I loved a girl in neighbor class. "]; NSString * str2 = [str1 stringbyreplacingoccurrencesofstring:@ ' Young, I loved a girl ' withstring:@ ' a teacher, I rather to Teach student "]; NSLog (@ "%@", str2); */* Method Four */nsmutablestring * str1 = [[nsmutablestring alloc]initwithstring:@] When I am young, I lov Ed a girl in neighbor class. "]; nsmutablestring * str2=[str1 stringbyreplacingoccurrencesofstring:@ "Young, I loved a Girl" withstring:@ ""]; [str2 insertstring:@ "a teacher, I rather to teach student" atindex:11]; NSLog (@ "%@", str2); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Extraction and substitution of strings in OC-four different methods of implementation