1.截取字符串
NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:7];//截取掉下标7之后的字符串
NSLog(@"截取的值为:%@",string);
[string substringFromIndex:2];//截取掉下标2之前的字符串
NSLog(@"截取的值为:%@",string);
2.匹配字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下标
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围类的字符串
NSLog(@"截取的值为:%@",string);
3.分隔字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组
NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf
NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:7];//截取掉下标7之后的字符串
NSLog(@"截取的值为:%@",string);
[string substringFromIndex:2];//截取掉下标2之前的字符串
NSLog(@"截取的值为:%@",string);
2.匹配字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下标
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围类的字符串
NSLog(@"截取的值为:%@",string);
3.分隔字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组
NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf
4.字符串在16位以后都用空代替(限制登录账号或者密码的位数时可以用到,这里是把字符串限制在16位以内)
userTF.text = [userTF.text stringByReplacingCharactersInRange:NSMakeRange(16, userTF.text.length - 16) withString:@"”];
5.字符串中是否包含“gm”
[string containsString:@"gm”]
6.判断字符串string1和string2是否相等
[string1 isEqualToString:@“string2"]