1. Case operation
// all uppercase result ABC [@ " ABC uppercasestring] // all lowercase // result BCD [@ " bcd " lowercasestring] // first uppercase // result ACB [@ " ACB " Capitalizedstring]
2. String comparisons
//Compare two strings for the same contentbool b =[str isequaltostring:str2];
// Two string content comparison //< Span style= "color: #008000;" > Nscomparisonresult result = {nsorderedascending, nsorderedsame,nsordereddescending } // nsorderedascending right > left // Nsorderedsame content same // nsordereddescending left > right Nscomparisonresult Result = [str compare:str2]; ignore case to compare
nscomparisonresult result = [str CASEINSENSITIVECOMPARE:STR2];
3. String Search
//determines whether a string starts with ABC[@ "ABCDFA"Hasprefix:@ "ABC"]; //determines whether a string is a BCD end[@ "ADBCD"Hassuffix:@ "BCD"]; //determines whether the string contains the specified string, returns the position and lengthNsrange range = [@ "123456"Rangeofstring:@ "456"]; //Reverse SearchNsrange range = [@"123456456qweasasd456"Rangeofstring:@"456"Options:nsbackwardssearch]; //Search by specified rangeNsrange range = Nsmakerange (0,9); Range= [@"123456456qweasasd456"Rangeofstring:@"456"Options:nsbackwardssearch Range:range];
Common methods of NSString in Foundation