OC Array Application example-verification code

Source: Internet
Author: User

//Generate random verification code

1 //Nsmutablearray *marr = [[Nsmutablearray alloc]init]; //The following variables are used to enter the object in a variable immutable group, respectively2 3Nsarray *arrtest =[[Nsarray alloc]init];4 5 for(inti =0; I <Ten; i++)6 {7 //[Marr Addobject:[nsnumber numberwithint:i];8 9Arrtest =[Arrtest arraybyaddingobject:[nsnumber numberwithint:i];Ten } One A for(inti ='a'; I <='Z'; i++) - { - //[Marr addobject:[nsstring stringwithformat:@ "%c", I]]; the -Arrtest = [Arrtest arraybyaddingobject:[nsstring stringWithFormat:@"%c", I]]; - } - + for(inti ='A'; I <='Z'; i++) - { + //[Marr addobject:[nsstring stringwithformat:@ "%c", I]]; A atArrtest = [Arrtest arraybyaddingobject:[nsstring stringWithFormat:@"%c", I]]; - } - //NSLog (@ "%@", arrtest); - - - //The second step produces a random digital output in - toNsmutablestring *mstr =[[nsmutablestring alloc]init]; +NSString *str =[[NSString alloc]init];; - for(inti =0; I <4; i++) the { *str = [arrtest objectatindex:arc4random ()%Arrtest.count]; $ [Mstr Appendstring:str];Panax Notoginseng - the //str = [Marr objectatindex:arc4random ()% marr.count]; + A //MSTR = [Mstr stringbyappendingstring:str]; the + //[Mstr Appendstring:str]; - } $NSLog (@"%@", MSTR); $ - - [Arrtest release]; the //[Marr release]; - [MSTR release];Wuyi [str release]; the

------The first step , put all the numeric uppercase letters into an array ------

//[NSString stringWithFormat: Convert other types to objects

[Mutstr appendformat:<# (NSString *), ...#> infrequently used

variable array Increment object is AddObject: non-variable group splicing object is arraybyaddingobject:

//character types also need to be converted to Objects

//immutable type can be overwritten again

--------The second step to randomly remove an object from the array----------

//variable string:appendString No return value is to add a string to the original string

concatenation of two strings into an immutable string: Stringbyappendingstring is a return value

OC Array Application example-verification code

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.