tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
20
Task/Reverse-a-string/Objective-C/reverse-a-string-1.m
Normal file
20
Task/Reverse-a-string/Objective-C/reverse-a-string-1.m
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSString (Extended)
|
||||
-(NSString *)reverseString;
|
||||
@end
|
||||
|
||||
@implementation NSString (Extended)
|
||||
-(NSString *) reverseString
|
||||
{
|
||||
NSUInteger len = [self length];
|
||||
NSMutableString *rtr=[NSMutableString stringWithCapacity:len];
|
||||
// unichar buf[1];
|
||||
|
||||
while (len > (NSUInteger)0) {
|
||||
unichar uch = [self characterAtIndex:--len];
|
||||
[rtr appendString:[NSString stringWithCharacters:&uch length:1]];
|
||||
}
|
||||
return rtr;
|
||||
}
|
||||
@end
|
||||
11
Task/Reverse-a-string/Objective-C/reverse-a-string-2.m
Normal file
11
Task/Reverse-a-string/Objective-C/reverse-a-string-2.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSString *test = [@"!A string to be reverted!" reverseString];
|
||||
|
||||
NSLog(@"%@", test);
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
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
|
||||
11
Task/Reverse-a-string/Objective-C/reverse-a-string-4.m
Normal file
11
Task/Reverse-a-string/Objective-C/reverse-a-string-4.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSString *test = [@"as⃝df̅" reverseString];
|
||||
|
||||
NSLog(@"%@", test);
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue