大醉和尚  
qq:3262641915,如有问题,欢迎讨论.

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
  1. std::string str("hello");  
  2. NSString *str=[NSString stringWithString:str.c_str()];

const char *str -->NSString

  1. char *str ="abc";  
  2. 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"];

posted on 2016-05-21 17:34  大醉和尚  阅读(129)  评论(0编辑  收藏  举报