Use the classification method, remove the space, count the number of characters

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.