久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

iOS開(kāi)發(fā) NSString字符串操作

 玄冰優(yōu) 2015-02-13
    NSString *content = @"<phone>12345678963</phone><address>78945612333</address>";
        NSRange str = [content rangeOfString:@"<address>"];
             
        
        //截取固定部分
        NSString *substr = [content substringWithRange:str];
        NSLog(@"address is %@",substr);
        
        // 拼接文件夾用
        NSString *try1 = [substr stringByAppendingPathComponent:content];
        NSLog(@"try 1 = %@",try1);
        
        // 拼接文件夾用 .
        NSString *try2 = [content stringByAppendingPathExtension:substr];
        NSLog(@"try 2 = %@",try2);
        
        // 截取從選定位置開(kāi)始 并指定長(zhǎng)度
        NSString *try3 = [content substringWithRange:NSMakeRange(str.location, 20)];
        NSLog(@"try3 = %@",try3);
        
        NSArray *try4 = [content componentsSeparatedByString:@">"];
        NSLog(@"try4 = %@",try4);
        
        // 從指定位置開(kāi)始截取
        NSRange range1 = NSMakeRange(str.location, str.length);        
        NSString *try5 = [content substringFromIndex:range1.location +range1.length];
        NSLog(@"try5 = %@",try5);
        
        //截取到指定位置
        NSRange str1 = [try5 rangeOfString:@"</address>"];
        NSRange range2 = NSMakeRange(str1.location, str1.length);
        NSString *try6 = [try5 substringToIndex:range2.location];
        NSLog(@"try6 = %@",try6);
        
//設(shè)置字符串首字母大寫(xiě)
     NSLog(@"str0首字母大寫(xiě):%@",[str0 capitalizedString]);
     //設(shè)置字符串全部?jī)?nèi)容為大寫(xiě)
     NSLog(@"str0大寫(xiě):%@",[str0 uppercaseString]);
     //設(shè)置字符全部?jī)?nèi)容為小寫(xiě)
     NSLog(@"str0小寫(xiě):%@",[str0 lowercaseString]);

//搜索查找

NSRange range = [str rangeOfString:@"345"];

if (range.location == NSNotFound) {

    //沒(méi)有找到

}


//截取
從第3個(gè)開(kāi)始到之后的
[str substringFromIndex:3];
截取到第5個(gè)
[str substringToIndex:5];
從第2個(gè)開(kāi)始 截取4個(gè)
[str substringWithRange:NSMakeRange(2, 4)];

// 關(guān)于大小寫(xiě)的轉(zhuǎn)化
//字符串轉(zhuǎn)換
NSString *str=@"abc";
NSString *str=@"ABC";
NSLog(@"uppercase:%@",[str uppercaseString]);//打印出ABC
NSLog(@"lowercase:%@",[stri lowercaseString]);//打印出abc

字符串轉(zhuǎn)化
NSString *str = @"100";

//轉(zhuǎn)int

int a = [str intValue];

//算字?jǐn)?shù)

int len = [str length];

//取字符

unichar c = [str characterAtIndex:0];

//返回c語(yǔ)言的字符串

char *s = [str UTF8String];

 

除了NSString,還有一個(gè)NSMutableString是可變字符串,,是NSString的子類,。

NSMutableString *str = [[NSMutableString alloc] initWithCapacity:8];

[str setString:@"1234"];
拼接
[str appendString:@"567890"];
替換
[str replaceCharactersInRange:[str rangeOfString:@"456"] withString:@"xxx"];
插入
[str insertString:@"yyy" atIndex:6];
刪除
[str deleteCharactersInRange:[str rangeOfString:@"xxyy"]];

NSLog(@"%@", str);




    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買(mǎi)等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多