1 #import "nsstring+extendstring.h"2 3 @implementationnsstring (extendstring)4 //1. Declare a string reversal (e.g. @ "123" to return @ "321" after calling the method)5+ (nsstring*) revertwithstring: (nsstring*) Str6 {7 //defines a mutable string8Nsmutablestring *string= [nsmutablestringstring];9 //2. Get the length of strTen intLength = (int) Str.length; One //3. Reverse Loop Traversal string A for(inti = length-1; I >=0; i-- ) - { - //4. Add the extracted characters to a mutable string the[stringAppendFormat:@"%c", [str characteratindex:i]]; - } - //5. Returns the string after reversal - return string ; + } - //2. Calculate the number of letters in English ++ (int) Countwithnum: (nsstring*) Str A{//1. Define an int variable to hold the number of occurrences of the letter at intCount =0; - for(inti =0; i < str.length; i++) - { -Unichar Uchar =[str characteratindex:i]; - if((Uchar <='Z'&&uchar >='a')|| (Uchar <='Z'&&uchar >='A')) - { incount++; - } to } + returncount; - } the //3. Remove both whitespace from the string *+ (nsstring*) trimwithstring: (nsstring*) Str $ {Panax Notoginseng //use the Stringbytrimmingcharactersinset method to remove special characters, call the static method Nscharacterset Whitespacecharacterset Remove the spaces at both ends. -NSString *string=[str stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]; the + return string; A } the @end
Use the classification method, remove the space, count the number of characters