用扩展sdk的方式添加nsstring 的一个方法,要求,讲传进去的字符串变成大写,去掉所有的空格,将所有的字符a变成“;”
用到类目了?刚学到这里不太懂
[解决办法]
@interface NSString(Custom)
-(void)hello;
@end
@implementation NSString(Custom)
-(void)hello{
NSLog(@"hello");
}
@end
ios开发超级群,来者注明来自CSDN:43146334
[解决办法]
@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