Skip to content

Instantly share code, notes, and snippets.

@SaitoWu
Created April 16, 2012 03:27
Show Gist options
  • Save SaitoWu/2396222 to your computer and use it in GitHub Desktop.
Save SaitoWu/2396222 to your computer and use it in GitHub Desktop.
oc open class.
//
// 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