美文网首页
字符串的倒序输出

字符串的倒序输出

作者: 阿兹尔 | 来源:发表于2016-12-20 16:22 被阅读30次

    -(NSString *)getReverseString:(NSString *)tempString
    {
    NSLog(@"%@",tempString);

    NSMutableString *mutableString =[NSMutableString stringWithString:tempString];
    
    for(int i = 0;i<tempString.length;i++)
    {
        
        NSString *subStr1 = [tempString substringWithRange:NSMakeRange(i, 1)];
        NSString *subStr2 = [tempString substringWithRange:NSMakeRange(tempString.length - i-1, 1)];
        
        NSRange range1 = [tempString rangeOfString:subStr1];
        NSRange range2 = [tempString rangeOfString:subStr2];
        
        
        [mutableString replaceCharactersInRange:range1 withString:subStr2];
        [mutableString replaceCharactersInRange:range2 withString:subStr1];
        
    }
    tempString = [NSString stringWithFormat:@"%@",mutableString];
    return tempString;
    

    }

    相关文章

      网友评论

          本文标题:字符串的倒序输出

          本文链接:https://www.haomeiwen.com/subject/bdqfvttx.html