Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Reverse-a-string/Objective-C/reverse-a-string-3.m
Normal file
20
Task/Reverse-a-string/Objective-C/reverse-a-string-3.m
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSString (Extended)
|
||||
-(NSString *)reverseString;
|
||||
@end
|
||||
|
||||
@implementation NSString (Extended)
|
||||
-(NSString *)reverseString
|
||||
{
|
||||
NSInteger l = [self length] - 1;
|
||||
NSMutableString *ostr = [NSMutableString stringWithCapacity:[self length]];
|
||||
while (l >= 0)
|
||||
{
|
||||
NSRange range = [self rangeOfComposedCharacterSequenceAtIndex:l];
|
||||
[ostr appendString:[self substringWithRange:range]];
|
||||
l -= range.length;
|
||||
}
|
||||
return ostr;
|
||||
}
|
||||
@end
|
||||
Loading…
Add table
Add a link
Reference in a new issue