oc--has such an integer 123456789, how to put the number of each digit of this integer, starting from the last place in the array, and traversing the reverse output string

Source: Internet
Author: User

There is an integer 123456789, how to put the number of each digit of this integer, starting from the last place in the array, and traversing
1Nsinteger num=123456789;2NSString *str=[[nsstring Alloc]initwithformat:@"%ld", num];3Nsmutablearray *arr=[Nsmutablearray array];4 for(Nsinteger i=str.length-1; i>=0; i--){5 //The string is truncated at the bottom, one at a time6NSString *str1=[str Substringwithrange:nsmakerange (i,1)];7 [arr addobject:str1];8 }9 //nsarray *sortarr=[arr sortedarrayusingselector: @selector (Class)];TenNSLog (@"first question-------------"); One for(IDStrincharr) { ANSLog (@"%@", str); -}
1 //How to invert the string @ "abc123.xyz789"2NSString *STR1 =@"Uoy Evol I";3Nsmutablestring *str2=[[nsmutablestring alloc]initwithcapacity:str1.length];4Nsuinteger len=[str1 length];5          for(Nsinteger i= (len-1) ; I >=0; i--) {6[STR2 AppendFormat:@"%c", [str1 characteratindex:i]];//Notice that the char is returned here7}

Convert May 05, 2013 to 2013-05-05

Convert May 05, 2013 to 2013-05-05

1Nsmutablestring *str3=[[nsmutablestring Alloc]initwithformat:@"May 05, 2013"];2NSLog (@"The third question-------------");3NSLog (@"Original date:%@", STR3);4Nsrange RANGE1=[STR3 rangeofstring:@"years"];5         6[Str3 Replacecharactersinrange:nsmakerange (range1.location-1, range1.length+2) Withstring:@"-"];7Nsrange RANGE2=[STR3 rangeofstring:@"Month"];8[Str3 Replacecharactersinrange:nsmakerange (range2.location-1, range2.length+2) Withstring:@"-"];9Nsrange RANGE3=[STR3 rangeofstring:@"Day"];Ten[Str3 Replacecharactersinrange:nsmakerange (Range3.location, range3.length) withstring:@""]; OneNSLog (@"Date converted:%@", STR3);

oc--has such an integer 123456789, how to put the number of each digit of this integer, starting from the last place in the array, and traversing the reverse output string

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.