[STR hasprefix: @ "12"]; // return value bool starting with 12
[STR hassuffix: @ "TXT"]; // whether to return bool at the end of txt
// Search for strings
[STR rangeofstring: @ "345"]; // returns the return location of the nsange parameter. If the return location is not found, {nsnotfound, 0} is returned}
// Search from the end
Nsange range = [STR rangeofstring: @ "456" Options: nsbackkwardssearch];
# Pragma mark string Truncation
Nsstring * STR = @ "123456 ";
// Truncate from index 3 to the end
Nslog (@ "% @", [STR substringfromindex: 3]); // print 456
// Truncate from the header to before index 3 (excluding 3)
Nslog (@ "% @", [STR substringtoindex: 3]); // print 123
// Intercept within the specified range
Nsange range = nsmakerange (2, 3 );
Nslog (@ "% @", [STR substringwithrange: range]); // print 345
Nsstring * str2 = @ "1, 2, 3, 4, 5 ";
// Separated by commas
Nsarray * array = [str2 componentsseparatebystirng: @ ","];
Nslog (@ "% @", array );
Nsstring * str3 = [array objectatindex: 0];
Nslog (@ "% @", str3); // print 1
Nsstring and Path:
# Pragma mark
Nsarray * components = [nsmutablearray array]; // nsmutablearray variable
[Components addobject: @ "users"];
[Components addobject: @ "gongpb"];
[Components addobject: @ "desktop"];
// Concatenates all strings in the array into a path
Nsstring * Path = [nsstring pathwithcompoents: components]; // print users/gongpb/desktop
Nslog (@ "% @", PATH );
Nsarray * CMPs = [path pathcomponents]; // Decomposition
Nslog (@ "% @", CMPs); // (users, gongpb, desktop)
Path = @ "users/gongpb/desktop/test ";
Nslog (@ "% I", [path isabsolutepath]); // 0 is returned to determine whether the front edge has a slash/
// The last folder
Nslog (@ "Last Directory: % @", [path lastpathcomponent]); // return test
// Delete the last folder
Nslog (@ "% @", [path stringbydeletinglastpathcomponent]); returns users/gongpb/desktop deleted/test
// Concatenate a spoof directory at the end
Nslog (@ "% @", [path stringbyappendingpathcomponent: @ "ABC"]); // return/users/gongpb/desktop/test/ABC
Nsstring * STR = @ "/user/gongpb/test.txt ";
Nslog (@ "% @", [STR pathextension]); // get the extension,
// Delete the extension
[STR stringbydeletingpathextension];
// Add Extension
[@ "ABC" stringbyappendingpathextension: @ "MP3"];
Other usage:
Nsstring * STR = @ "12 ";
Int A = [STR intvalue]; // convert int
// Calculate the number of words, not the number of characters
[STR length];
// Obtain characters
Unichar c = [@ "ABC" characteratindex: 0];
Nslog (@ "% C", C );
// Returns the const string in the C language, indicating that S is a constant.
Const char * s = [@ "ABC", utf8string];
Nslog (@ "% s", S );