Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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()
|
||||
{
|
||||
@autoreleasepool {
|
||||
|
||||
NSString *test = [@"!A string to be reverted!" reverseString];
|
||||
|
||||
NSLog(@"%@", test);
|
||||
|
||||
}
|
||||
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()
|
||||
{
|
||||
@autoreleasepool {
|
||||
|
||||
NSString *test = [@"as⃝df̅" reverseString];
|
||||
|
||||
NSLog(@"%@", test);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue