星空网 > 软件开发 > 操作系统

NSString 的常用操作

 

    NSString *testStr01=@"HelloWord";    NSString *testStr02=[testStr01 substringToIndex:5];//取头(从头到哪),to不包括下标内容    NSString *testStr03=[testStr01 substringFromIndex:5];//去尾(从哪到尾),from包括下标内容    NSLog(@"testStr02:%@ testStr03:%@",testStr02,testStr03);        NSRange r={4,3};//取中间,从哪长度是多少    NSString*testStr04=[testStr01 substringWithRange:r];    NSLog(@"testStr04:%@",testStr04);                //字符串的拼接    NSString *testStr05 = @"Hello";    //追加    NSString *testStr06 = [testStr05 stringByAppendingString:@"World"];    NSLog(@"testStr06:%@",testStr06);    //初始化    NSString *testStr07 = @"Hello";    NSString *testStr08 = @"World";    NSString *testStr09 = [NSString stringWithFormat:@"%@%@",testStr07,testStr08];    NSString *testStr10 = [NSString stringWithFormat:@"Hello%@",testStr08];    NSLog(@"testStr09:%@",testStr09);    NSLog(@"testStr10:%@",testStr10);            //按指定格式(范围)追加内容    NSString *testStr11 = @"Hello";    NSString *testStr12 = [testStr11 stringByAppendingFormat:@"%@%@",@"World",@"123"];    NSLog(@"testStr12:%@",testStr12);            //替换    NSString *testStr13 = @"www.kyle.com.cn";    NSString *testStr14 = [testStr13 stringByReplacingCharactersInRange:NSMakeRange(4, 6) withString:@"163"];    NSLog(@"testStr14:%@",testStr14);            //编码集    //参数 文件的路径 不包括文件名    NSString *path = @"/Users/apple/Desktop";    //path = [path stringByAppendingString:@"/test.txt"];    path = [path stringByAppendingString:@"/test.rtf"];    //把文件中的内容 读取到字符串中    //NSString *str20 = [[NSString alloc]initWithContentsOfFile:path];        NSString *testStr15 = [[NSString alloc]initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];        NSLog(@"testStr15:%@",testStr15);            NSString* use=@"fcp";    NSString* use1=@"fcp";        NSString*password=@"123";    NSString*password1=@"123";    if ([use isEqualToString:use1]&&[password isEqualToString:password1]) {      NSLog(@"登陆成功");    }    else{      NSLog(@"登陆失败");    }      

 




原标题:NSString 的常用操作

关键词:string

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

运国际包裹:https://www.goluckyvip.com/tag/102591.html
国际包裹液体:https://www.goluckyvip.com/tag/102592.html
寄国际包裹有包装有什么要求:https://www.goluckyvip.com/tag/102593.html
ems国际包裹收费标准:https://www.goluckyvip.com/tag/102594.html
寄国外包裹怎么收费:https://www.goluckyvip.com/tag/102595.html
深圳欧洲小包:https://www.goluckyvip.com/tag/102596.html
价格翻了8倍,居然还有人买,秘诀在这里。:https://www.kjdsnews.com/a/1836642.html
欧洲B2B电商市场有待挖掘!销售总额将达1.7万亿欧元:https://www.kjdsnews.com/a/1836643.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流