Algorithm-string inversion

Source: Internet
Author: User

String anyway work sometimes encounter, in fact, with the previous integer reverse output is a truth, of course, there are a lot of methods of implementation, some people write seven kinds of, can achieve good, commonly used to achieve two kinds, make a look at it:

Reverse.h

@interface reverse:nsobject-(void) reverse;-(NSString *) Reverse1: (NSString *) str; @end

REVERSE.M's Code:

@implementation reverse-(void) reverse{    char  arr[]= "flyelephant";    Nsinteger  Count=strlen (arr);    for (Nsinteger i=0; i<count/2; i++) {        char  temp=arr[i];        ARR[I]=ARR[COUNT-I-1];        arr[count-i-1]=temp;    }    NSLog (@ "Current string:%s", arr);} -(NSString *) Reverse1: (NSString *) str{    nsstring *[email  protected] "";    for (Nsinteger i=str.length-1; i>=0; i--) {        char  temp=[str characteratindex:i];        Result=[result stringbyappendingstring:[nsstring stringwithformat:@ "%c", temp]];    }    return result;} @end

Call:

         Reverse  *reverse=[[reverse Alloc]init];        [Reverse reverse];        NSLog (@ "The result of the final output is:%@", [Reverse reverse1:@ "Http://www.cnblogs.com/xiaofeixiang"]);        NSLog (@ "iOS technology Group: 228407086");

Effect:

 

Algorithm-string inversion

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.