#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
NSString Parent class nsmutablestring variable string subclass
Nsmutablestring *mustr=[[nsmutablestring Alloc]init];
Nsmutablestring *mustr1=[nsmutablestring stringwithformat:@ "Hello"];
Place immutable strings inside a mutable string
NSString *[email protected] "Welcome to OC";
Mustr=[nsmutablestring STRINGWITHSTRING:STR];
Insert
[Mustr insertstring:@ "Students" atindex:7];
[Mustr appendstring:@ "Teacher"];
[Mustr appendformat:@ "second pass insert:%@", str];
Delete
[Mustr Deletecharactersinrange:nsmakerange (8, 10)];
Find and delete
Nsrange rang=[mustr rangeofstring:@ "second pass insert: Welcome to OC"];
if (rang.location!=nsnotfound) {
[Mustr Deletecharactersinrange:rang];
}
Re-assign Value
[Mustr SETSTRING:STR];
Replace
Nsrange rang1=[mustr rangeofstring:@ "OC"];
[Mustr replacecharactersinrange:rang1 withstring:@ "IOS"];
NSLog (@ "%@", mustr);
Determines whether a string has a prefix
NSString *[email protected] "ios8-Zhao Yuxin. jpg";
BOOL result = [str hasprefix:@ "IOS"];
NSLog (@ "%d", result);
Determines whether a string has a suffix
BOOL Resultsu = [str hassuffix:@ ". jpg"];
NSLog (@ "%d", Resultsu);
Length
1. Defining a String Object
NSString *str=[nsstring stringwithstring:@ "Zi fu Chuan"];
2. Calculating string Lengths
Nsuinteger len = [str length];
3. Output string length
NSLog (@ "Zi fu chuan length is%ld", Len);
}
return 0;
}
Variable string insertion Delete re-assignment replace prefix length