------ Java training, Android training, IOS training, and. Net training. We look forward to communicating with you! -------
Common classes
Nsstring
-> Nsmutablestring
Nsarray
-> Nsmutablearray
Nsset
-> Nsmutableset
Nsdictionary
-> Nsmutabledictionary
Nsdate
Nsobject
Character class-nsstring/nsmutablestring
Nsstring: unchangeable string
Nsmutablestring: Variable string
1 void stringcreate () 2 {3/* 4 1. create 5 */6 nsstring * S1 = @ "Jack"; 7 8 // nsstring * S2 = [[nsstring alloc] initwithstring: @ "Jack"]; 9 10 nsstring * S3 = [[nsstring alloc] initwithformat: @ "Age is % d", 10]; 11 12 // C string --> OC string 13 nsstring * S4 = [[nsstring alloc] initwithuf8string: "Jack"]; 14 // OC string --> C string 15 const char * cs = [S4 utf8string]; 16 17 // nsutf8stringencoding can be used in Chinese to encode 18 nsstring * S5 = [[nsstring alloc] initwithcontentsoffile: @ "/users/Apple/desktop/1.txt" encoding: nsutf8stringencoding error: nil]; 19 20 21 // URL: Resource path 22 // protocol header: // path 23 // file: // 24 // ftp: // 25 // http://weibo.com/a.png26 27 28 29 30 // nsurl * url = [[nsurl alloc] initwithstring: @ "file: // users/Apple/desktop/1.txt"]; 31 nsurl * url = [nsurl fileurlwithpath: @ "/users/Apple/desktop/1.txt"]; 32 33 nsstring * S6 = [[nsstring alloc] initwithcontentsofurl: URL encoding: nsutf8stringencoding error: nil]; 34 nslog (@ "S6 = \ n % @", S6); 35 36 37/* 38 there is usually a class method paired with the object method 39 [nsurl urlwithstring: <# (nsstring *) #>]; 40 [nsstring stringwithformat: @ ""]; 41 [nsstring stringwithcontentsoffile: <# (nsstring *) #> encoding: <# (nsstringencoding) #> error: <# (nserror * _ autoreleasing *) #>]; 42 43 */44 45}
1 void stringexport () 2 {3 // export string 4 [@ "Jack \ njack" writetofile: @ "/users/Apple/desktop/my.txt" atomically: Yes encoding: nsutf8stringencoding error: Nil]; 5 6 7 nsstring * STR = @ "4234234"; 8 nsurl * url = [nsurl fileurlwithpath: @ "/users/Apple/desktop/my2.txt"]; 9 [STR writetourl: URL atomically: Yes encoding: nsutf8stringencoding error: Nil]; 10}
1 void stringexport () 2 {3 nsmutablestring * S1 = [nsmutablestring stringwithformat: @ "My age is 10"]; 4 // splice the content to the next 5 [S1 appendstring: @ "11 12"]; 6 7 // obtain the is range. 8: nsange range = [S1 rangeofstring: @ "is"]; 9 // Delete 10 [S1 deletecharactersinrange: range]; 11 12 13 nsstring * S2 = [nsstring stringwithformat: @ "Age is 10"]; 14 // a new string of 15 16 nsstring * S3 = [S2 stringbyappendingstring: @ "11 12"]; 17 18 19 nslog (@ "S1 = % @, S2 = % @", S1, S2); 20 21 return 0; 22}
[Dark horse programmer] ---- foundation framework 02 common classes-character classes