用到类目了?刚学到这里不太懂

解决方案 »

  1.   

    @interface NSString(Custom)-(void)hello;@end@implementation NSString(Custom)
    -(void)hello{
         NSLog(@"hello");
    }
    @end
    ios开发超级群,来者注明来自CSDN:43146334
      

  2.   

    @implementation NSString(Custom)
    -(NSString*)myFunc
    {    //传进去的字符串变成大写
        NSString* upper = [self uppercaseString];
        
        //去掉所有的空格
        NSMutableString* filterString = [[[NSMutableString alloc] init] autorelease];
        
        NSArray* array   = [upper componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
        
        for (NSString* str  in array)
        {
            [filterString appendString:str];
        }
        //将所有的字符a(A)变成“;”
        [filterString replaceOccurrencesOfString:@"A" withString:@";" options:NSBackwardsSearch range:NSMakeRange(0, [filterString length])];
        return filterString;
    }
    @end