现在的位置: 首页 > 综合 > 正文

OC 字符串操作

2014年10月09日 ⁄ 综合 ⁄ 共 986字 ⁄ 字号 评论关闭

/--------操作字符串--NSString(静态字符串)---------------------
    NSString
*Beijing= @"北京欢迎您"; 
       //字符串的声明
    NSString
*log=@"北京欢迎您a"; //[NSString stringWithFormat:@"I am '%@'",Beijing]; 
    //字符串格式化
    NSString
*zhui = [Beijing stringByAppendingString:@"哈哈哈"]; 
       //字符串追加
    bool
b=[Beijing isEqualToString:log]; 
                              //字符串比较
    NSString
*hh = @"http://www.sina.com.cn";

    if([hh
hasPrefix:@"http"]){ 
                                         //查找以http开头的字符串
        NSLog(@"含有http");
    }else{
        NSLog(@"没有http");
    }
    NSString
*ss = @"123";

    int
a = [ss intValue]+13; 
                                  //字符串转int型
    double
dd = [ss doubleValue]+33.3; 
                         //字符串转double型
    NSLog(@"%g",dd);
//字符串转数组 
    NSString
*zifuchuan =@"one,two,three,four";

    NSLog(@"string:%@",zifuchuan);
    NSArray
*array = [zifuchuan componentsSeparatedByStr
ing:@","];
//    NSLog(@"array:%@",array);                             //输出整个数组中所有元素 
    NSString
*value = [array objectAtIndex:0]; 
   

抱歉!评论已关闭.