Reverse a string: Difference between revisions

Content deleted Content added
Line 614: Line 614:


@implementation NSString (Extended)
@implementation NSString (Extended)
-(NSString *)reverseString
-(NSString *) reverseString
{
{
NSUInteger len = [self length];
NSInteger l;
NSMutableString *ostr = [NSMutableString stringWithCapacity:[self length] ];
NSMutableString *rtr=[NSMutableString stringWithCapacity:len];
// unichar buf[1];
for(l=[self length]-1; l>=0; l--)
{
while (len > (NSUInteger)0) {
[ostr appendFormat:@"%C", [self characterAtIndex:l] ];
unichar uch = [self characterAtIndex:--len];
}
[rtr appendString:[NSString stringWithCharacters:&uch length:1]];
return ostr;
}
return rtr;
}
}
@end</lang>
@end</lang>