温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

<Foundation>框架 String字符串处理 连载3

发布时间:2020-06-11 22:55:41 来源:网络 阅读:441 作者:平凡51 栏目:开发技术

     

<Foundation>框架 String字符串处理

 //此函数为<foundationt>框架下字符串类的操作方法

         //常用类的创建

//       //NSNumber的创建

//        NSNumber *str = [[NSNumberalloc] initWithInt:100];

//        NSLog(@"%@",str);

//        NSNumber *str1 = [NSNumbernumberWithInt:100];

//        NSLog(@"%@",str1);

//

       

//       //NSString对象的创建

//        NSString *str2 =@"zhuguolu";   //快捷创建

         //alloc创建

//        NSString *str3 = [[NSStringalloc] initWithString:@"dopibichen"];

         //格式化符创建alloc方法)

//        int a = 100;

//        NSString *str4 = [[NSStringalloc] initWithFormat:@"zhoudiaodiao",a];

//        //格式化符创建 (类方法创建)

//        NSString *str5 = [NSStringstringWithFormat:@"hehehe", a];

//        NSLog(@"str2 = %@ , str3= %@ , str4 = %@, str5 = %@",str2,str3,str4,str5);

//

       

       //比较字符串内容是否相同

//        NSString *s1 = [NSStringstringWithFormat:@"hehe"];

//        NSString *s2 = [NSStringstringWithFormat:@"heh"];

//        if (s1 == s2){        //(比较的是地址)

//            NSLog(@"success");

//           NSLog(@"%p ,%p",s1,s2);

//        }else {

//           NSLog(@"loss");

//           NSLog(@"%p ,%p",s1,s2);

//        }

       

       //比较字符串内容是否相同

//        NSString *s1 = [NSStringstringWithFormat:@"hehe"];

//        NSString *s2 = [NSStringstringWithFormat:@"heh"];

//        if ([s1 isEqualToString:s2]){  //比较的是内容

//           NSLog(@"true");

//        }else {

//           NSLog(@"wrong");

//        }

       

       //比较字符串的大小

//        NSString *s1 = [NSStringstringWithFormat:@"hehe"];

//        NSString *s2 = [NSStringstringWithFormat:@"heh"];

//        NSComparisonResult result =[s1 caseInsensitiveCompare:s2];

//        if (result ==NSOrderedAscending) {

//           NSLog(@"升序排列s1 <s2");

//        } else if(result ==NSOrderedSame){

//           NSLog(@"内同相同s1 = s2");

//        } else if(result ==NSOrderedDescending){

//           NSLog(@"降序排列s1 >s2");

//        }

       

 

       //求字符串长度

//        unsigned int a = [s1 length];

//        NSLog(@"a = %u",a);

//      //unsigned int len = strlen(s1);  //注意这里NSString是一个字符串对象

 

       //转换大小写

//        NSString *he = @"hellowworld";

//        NSLog(@"he is%@",[he uppercaseString]);//全部大写

//        NSLog(@"he is%@",[he lowercaseString]);//全部小写

//        NSLog(@"he is%@",[he capitalizedString]);//首字母大写

       

       //转换为基本数据类型

//        NSString *str =@"10";

//        int b = [str intValue];

//        NSLog(@"%d",b);//还可以转换成char BOOL类型等

       

//        //分割字符串

//        NSString *str = @"welcom,henan,caijing,unisivity";

//        NSArray *arr =[strcomponentsSeparatedByString:@","];

//        for (int i = 0; i < 4;i++) {

//           NSLog(@"%@  ",arr[i]);

//        }

       

       //访问指定位置字符

//        NSString *str =@"welcom,henan,caijing,unisivity";

//        char a = [strcharacterAtIndex:0];

//        NSLog(@"%c",a);

 

       

//        //字符串截取

//        NSString *str = @"welcomhenancaijing unisivity";

//        NSString *s1 = [str substringToIndex:7];//截取到指定位置

//        NSString *s2 = [strsubstringFromIndex:13];//从之定位值开始截取

//        NSRange ran = NSMakeRange(3,7);//第一个参数为位置、第二个参数为数量

//        NSString *s3 = [strsubstringWithRange:ran];//范围截取,从指定位置截取几个

//       

//        NSLog(@"s1 = %@ , s2 =%@ , s3 = %@ ",s1,s2,s3);

       

//        //字符串拼接

//        NSString *str1 =@"hellow";

//        NSString *str2 =@"china";

//        NSString *str = [NSStringstringWithFormat:@"%@ %@",str1,str2];

//        NSLog(@"str is%@",str);

//       

//        NSString *str3 = [str1stringByAppendingString:str2];

//        NSString *str4 = [str1stringByAppendingFormat:@" %@",str2];//追加字符串str2

//        NSLog(@"str3  = %@, str4 = %@",str3,str4);

       

 

//        //查找字符串

//        NSString *str1 = @"123423@qq.com";

//        NSString *str2 = @"qq.com";

//        NSString *str3 = @"163.com";

//        NSRange ran = [str1rangeOfString:str2];

//        if (ran.location != NSNotFound){

//           NSLog(@"%@包含%@ ",str1,str2);

//           NSLog(@"位置是:%ld长度是:%ld",ran.location,ran.length);

//        } else {

//           NSLog(@"%@中没有找到%@",str1,str2);

//        }

       

//        //更换字符

//        NSString *str = [str1stringByReplacingOccurrencesOfString:str2 withString:str3];

//        NSLog(@"str is%@",str);

       

//        //可变字符串

//       //..插入字符串

//        NSMutableString *str =[NSMutableString stringWithString:@"hi  "];

//        NSLog(@"%@",str);

//        [strinsertString:@"hellow" atIndex:4];

//        NSLog(@"%@",str);

//       

//        //..删除字符串

//        NSRange ran = NSMakeRange(2,1);

//        [strdeleteCharactersInRange:ran];

//        NSLog(@"%@",str);

//       

//        //..追加字符串

//        [str appendString:@"China"];

//        NSLog(@"%@",str);

 

<Foundation>框架 String字符串处理 连载3

<Foundation>框架 String字符串处理 连载3

<Foundation>框架 String字符串处理 连载3


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI