Created
April 16, 2012 03:27
-
-
Save SaitoWu/2396222 to your computer and use it in GitHub Desktop.
oc open class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// koans | |
// | |
// Created by Saito on 4/13/12. | |
// Copyright (c) 2012 Yava Exchange. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSString (RemoveSuffix) | |
- (NSString *)stringByRemovingSuffix:(NSString *)suffix; | |
@end | |
@implementation NSString (RemoveSuffix) | |
- (NSString *)stringByRemovingSuffix:(NSString *)s { | |
NSString *result; | |
if([self hasSuffix:s]) | |
result = [self substringToIndex:[self length] - [s length]]; | |
return result; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString *hello = @"Hello World"; | |
NSString *x = [hello stringByRemovingSuffix:@"World"]; | |
NSLog(@"%@", x); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment