Determines whether the input string is a plain or pure letter

Source: Internet
Author: User

Summary:
    • Nsscanner:nsscanner is a class that is used to scan a string for specified characters, especially translating/converting them to numbers and other strings. You can specify the string property of Nsscaner when you create it, and then scanner will scan each character of the string from start to finish as you ask.
    • Nscharacterset: It is used primarily to determine whether a known string contains a character set and cannot be used to hold a string.

1. Use Nsscanner to determine

To determine whether to reshape:-(BOOL) Ispureint: (nsstring*) string{nsscanner* scanner = [nsscanner scannerwithstring:string]; int Val; return[scan scanint:&val] && [scan isatend];} //determines whether it is a floating-point shape:-(bool) Ispurefloat: ( nsstring*) string{nsscanner* scan = [ nsscanner scannerwithstring:string]; float Val; return[scan scanfloat:&val] && [scan isatend];} if (![ self Ispureint:str1] | | ! [self Ispurefloat:str1]) {Alert.text = @ "Warning: contains illegal characters, please enter a pure number! "; return;}             



2. Using Nscharacterset

  • (Nscharacterset *) Controlcharacterset; Control character
  • (Nscharacterset *) Whitespacecharacterset; Space
  • (Nscharacterset *) whitespaceandnewlinecharacterset;//first space
  • (Nscharacterset *) Decimaldigitcharacterset; Decimal digits
  • (Nscharacterset *) Lettercharacterset; Text
  • (Nscharacterset *) Lowercaselettercharacterset; lowercase letters
  • (Nscharacterset *) Uppercaselettercharacterset; Capital
  • (Nscharacterset *) Nonbasecharacterset; Non-basic
  • (Nscharacterset *) Alphanumericcharacterset; Alpha-Numeric
  • (Nscharacterset *) Decomposablecharacterset; Can be decomposed
  • (Nscharacterset *) Illegalcharacterset; Illegal
  • (Nscharacterset *) Punctuationcharacterset; Punctuation
  • (Nscharacterset *) Capitalizedlettercharacterset; Capital
  • (Nscharacterset *) Symbolcharacterset; Symbol
  • (Nscharacterset *) Newlinecharacterset ns_available (10_5, 2_0);//Line break

Determine if it is a pure letter-(BOOL) Ispurecharacters: (NSString *) string{string = [string stringbytrimmingcharactersinset:[Nscharacterset Lettercharacterset]];if (string. length >0) {ReturnNO; }ReturnYES;}Determine if it is a pure number-(BOOL) Ispurenum: (NSString *) string{string = [string stringbytrimmingcharactersinset:[Nscharacterset Decimaldigitcharacterset]];if (string. length >0) {ReturnNO; }ReturnYES;}Determines whether a contiguous array or letter is included, yes contains-(BOOL) Rangestring: (NSString *) String {BOOL result =NO; For (int i = 0, i < string. Length; i++) { if (string. Length-i < 4) {break ;} 
                                       
                                        nsstring *newstr = [string Substringwithrange:
                                        nsmakerange (i, 4)]; if ([selfispurecharacters:newstr] | | [Selfispurenum:newstr]) { NSLog (@ "%@", newstr); result = YES; Break ;} } return result;          
                                             

Determine if the input string is a plain or plain letter

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.