TA的每日心情 | 汗 2024-10-15 10:05 |
---|
签到天数: 372 天 [LV.9]以坛为家II
|
NSString+Reverse.h
- #import <Foundation/Foundation.h>
- @interface NSString(reverse)
- - (NSString *) reverseString;
- @end
复制代码
NSString+Reverse.m
- #import <Foundation/Foundation.h>
- #import "NSString+Reverse.h"
- @implementation NSString (reverse){
- - (id) reverseString{
- NSUinteger len = [self length];
- NSMutableString * retStr = [NSMutableString stringWithCapacity:len];
- while(len>0){
- unichar c = [self characterAtIndex:--len];
- NSString * str = [NSString stringWithFormat:@"%C",c];
- [retStr appendString:str];
- }
- return retStr;
- }
- }
- @end
复制代码
main.m- #import <Foundation/Foundation.h>
- #import "NSString+Reverse.h"
- int main(int argc, const char * argv[])
- {
- NSAutoreleasePool = [[NSAutoreleasePool alloc] init];
- NSString * str = [NSString stringWithString:@"Hello World"];
- NSLog(@"String:%@",str);
- NSString * rev = [str reverseString];
- NSLog(@"Reversed:%@",rev);
- [pool drain];
- }
复制代码
|
|