转载来源 NSCharacterSet其实是许多字符或者数字或者符号的组合,在网络处理的时候会用到 NSMutableCharacterSet *base = [NSMutableCharacterSet lowercaseLetterCharacterSet]; //字母 NSCharacterSet *decimalDigit = [NSCharacterSet decimalDigitCharacterSet BOOL)isPureNumandCharacters:(NSString *)string { string = [string stringByTrimmingCharactersInSet:[NSCharacterSet
https://blog.csdn.net/u010105969/article/details/47043073 NSCharacterSet * set = [NSCharacterSet arrayWithArray:arr2]; [array1 removeObject:@""]; [array1 removeObject:@""]; 上面是一个分割字符串的例子,这里用到了NSCharacterSet
过滤特定字符 NSCharacterSet *filterSet = [NSCharacterSet characterSetWithCharactersInString:@"[]{}(#%-*+=_)
YES; } } return NO; } 2、过滤特殊字符串 + (NSString *)isSpecialCharacter:(NSString *)str{ NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、[]{}%-+=_\\|~<>$€^•'@$% ]; NSScanner *scanner = [NSScanner scannerWithString:originalString]; // 提取包含0-9和*#的字符串 NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789*#"]; while (!
,则将NSArray转化为NSMutableArray NSArray * array2 = [ptr componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@", "]];//以字符串中的字符作为分割条件进行分割 《字符集合》 NSCharacterSet 这是个字符集合类 [NSCharacterSet characterSetWithCharactersInString:@", "]//把字符串转化为字符集合
方法2:(推荐) 使用到的API - (nullable NSString *)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet p1=abc&p2=我是参数2"; NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet]; NSString stringByAddingPercentEncodingWithAllowedCharacters用法 stringByAddingPercentEncodingWithAllowedCharacters接收NSCharacterSet 对象,几种常用的NSCharacterSet: URLFragmentAllowedCharacterSet "#%<>[\]^`{|} URLHostAllowedCharacterSet
=0&style=2", toCoor.latitude, toCoor.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet toCoor.latitude, toCoor.longitude, targetName] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet 1&policy=0", toCoor.latitude, toCoor.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet targetName, toCoor.latitude, toCoor.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
initWithString:text.uppercaseString]; NSScanner *scanner = [NSScanner scannerWithString:text]; NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; while (!
name=北京&mode=driving&coord_type=gcj02",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet %@&dev=0&style=2",@"导航功能",@"nav123456",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet directionsmode=driving",@"导航测试",@"nav123456",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet tocoord=%@,%@&to=终点&coord_type=1&policy=0",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
去除两端空格 NSString *temp = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet ]]; 去除两端空格和回车 NSString *text = [temp stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet
self.contentTextField) { // 4位分隔银行卡卡号 NSString *text = [textField text]; NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789\b"]; string =
*)text { NSString *strResult = nil; NSMutableString *originString = [text mutableCopy]; NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:@"~!
val] && [scan isAtEnd]; } //是否只含有数字 + (BOOL)validateNumber:(NSString*)number { BOOL res = YES; NSCharacterSet * tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; int i = 0; while (i
NSLocale *)locale; //////////搜索字符集合////////// //12.搜索(指定字符集合) - (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)searchSet; //13.搜索(指定字符集合,条件) - (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)searchSet options :(NSStringCompareOptions)mask; //14.搜索(指定字符集合,条件,范围) - (NSRange)rangeOfCharacterFromSet:(NSCharacterSet D, E, F) //分割(指定字符集合) NSArray *resultArr2 = [string componentsSeparatedByCharactersInSet:[NSCharacterSet af"; //////////修剪////////// NSString *result1 = [string stringByTrimmingCharactersInSet:[NSCharacterSet
NSRange)range replacementString:(NSString *)string { NSString *text = [textField text]; NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789\b"]; string =
id=%@",@"testId"] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet [[NSString stringWithFormat:@"file://%@",path] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
验证格式 @return BOOL */ - (BOOL)inputTypeVerification:(NSString *)aStr format:(NSString *)format{ NSCharacterSet * filterCS = [[NSCharacterSet characterSetWithCharactersInString:format] invertedSet]; NSString *
里的字符都找出来(包含去空格功能)替换成"" truePhone = [[truePhone componentsSeparatedByCharactersInSet:[[NSCharacterSet if(self.model.isgetPhone){ textField.text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet textField.text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet
NSURL *url = [NSURL URLWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
似乎只能去除头尾的特殊字符(不准) + (NSString *)filterSpecialWithString:(NSString *)string { // 定义一个特殊字符的集合 NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString: @ "@/:;: ;()? + (BOOL)checkIdentityCardNo:(NSString*)value { value = [value stringByTrimmingCharactersInSet:[NSCharacterSet