switch(NSString):
#define CASE(str) if ([__s__ isEqualToString:(str)])
#define SWITCH(s) for (NSString *__s__ = (s); ; )
#define DEFAULT
SWITCH (string) {
CASE (@"AAA") {
break;
}
CASE (@"BBB") {
break;
}
CASE (@"CCC") {
break;
}
DEFAULT {
break;
}
}
++ std::string 和NSString 互相转换
const char *str -->NSString
- std::string str("hello");
- NSString *str=[NSString stringWithString:str.c_str()];
const char *str -->NSString
- char *str ="abc";
- SString *s = [NSString stringWithUTF8String:str];
NSString --> std::string
std::string str = "hello";
NSString *string = [str UTF8String];
NSURL与NSString相互转换
1 NSURL转换成NSString
NSString * urlStr = [url absoluteString];
2 NSString转换成NSURL
NSURL * url = [NSURL URLWithString:urlStr];
NSURL * url = [[NSURL alloc] initWithString:urlStr];
NSNumber-->NSString
NSString *myString = [NSNumber stringValue];
NSString-->NSNumber
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
NSNumber *myNumber = [f numberFromString:@"42"];