1. Creation of strings
1: @ "Jack";
2:
3: //nsstring *s2 = [[NSString alloc] initwithstring:@ "Jack"];
4:
5: nsstring *s3 = [[NSString alloc] Initwithformat:@ "Age is%d", 10];
6:
7: //C string > C string
Ten: constchar *cs = [S4 utf8string];
11:
Nsutf8stringencoding : //Use this code in Chinese
: nsstring *s5 = [[NSString alloc] Initwithcontentsoffile:@ "/users/apple/desktop /1.txt " encoding:nsutf8stringencoding Error:nil];
14:
1: /*
2: There will always be a class method paired with the object method
3: [Nsurl urlwithstring:<# (NSString *) #>];
4: [NSString stringwithformat:@ ""];
5: [NSString stringwithcontentsoffile:<# (NSString *) #> encoding:<# ( nsstringencoding) #> error:<# (nserror *__autoreleasing *) #>];
6:
7: * /
2. Common methods
1) Check the prefix
1: @ "Qq=12344&pwd=adadfs";
2: [str hasprefix:@ "qq="];
3:
4: [str hassuffix:@ "FS"];
2) uppercase and lowercase conversions
1: nsstring *str = [@ "Adbdad" lowercasestring];
2: nsstring *upstr = [str uppercasestring];
3: NSLog (@ "%@", UPSTR);
4: // [[@ "Adbdad" lowercasestring] isequaltostring:@ "ADSFASD" ];
3) Variable string
1: nsmutablestring *str = [[Nsmutablestring alloc] initwithcapacity:0];
2:
3: [str appendformat:@ "123"]; //123
4: // NSLog (@ "%@", str);
5: //
6: // NSString *str1 = @ "123";
7: // NSString *str2 = [str1 stringbyappendingstring:@ "AAAA"];
8: // NSLog (@ "%@", str2);
9: //
: nsrange rang3 = [str rangeofstring:@ "3"];
One : [str deletecharactersinrange:rang3];
: NSLog (@ "%@", str);
13:
: [str insertstring:@ "AAA" atindex:0];
15:
+ : //@ "3" @ ""
+ : [str replaceoccurrencesofstring:@ "3"
: withstring:@ ""
: Options:nsliteralsearch
: range:nsmakerange (0, str.length)];
: NSLog (@ "%@", str);
Dark Horse programmer--"Dark Horse video note" OC Language Foundation NSString