The primary operation for nsmutablestring mutable strings is to create, add, delete, insert, replace
The code operates as follows:
1 //2 //main.m3 //03-nsmutablestring4 //5 //Created by Ma C on 15/8/17.6 //Copyright (c) 2015 BJSXT. All rights reserved.7 //8 9 #import<Foundation/Foundation.h>Ten One intMainintargcConst Char*argv[]) A { - @autoreleasepool - { the //common operations for variable strings - //1. Create (give a fixed capacity) -nsmutablestring *str1 = [nsmutablestring stringwithcapacity: +]; - //2. Add content (add at trailer) +[Str1 appendString:@"Hello World"]; -NSLog (@"str1 =%@", str1); +[Str1 AppendFormat:@"%d",123]; ANSLog (@"str1 =%@", str1); at - //3. Inserting content at the index -[Str1 insertstring:@"OK"Atindex:6]; -NSLog (@"%@", str1); - - //4. Replace content inNsrange range = [str1 rangeofstring:@" World"]; -[Str1 replacecharactersinrange:range withstring:@" World"]; toNSLog (@"%@", str1); + - //5. Delete Content the [str1 Deletecharactersinrange:range]; *NSLog (@"%@", str1); $ Panax Notoginseng //6. Fully set to other strings -[Str1 setString:@" How is You"]; theNSLog (@"%@", str1); + A } the return 0; +}
Common operations for the Objective-c:nsmutablestring class