1.字符xString串前面是否包含aString
BOOL isHavePrefix = [xString hasPrefix:aString];
包含返回YES,不包含返回NO。
2.NSString过滤
2.1自带方法,可以去除用户输入的前后空格(注意只是前后哦)或是里面的特殊符号
NSString *newStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
2.2 NSCharacterSet其实是许多字符或者数字或者符号的集合,如果需要过滤用户输入的字符串,需要自行创建NSCharacterSet对象,并且输入要过滤的字符
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@/:();()¥「」"、[]{}#%-*+=_\\|~<>$€^•'@#$%^&*()_+'\""];
2.3 NSCharacterSet提供了很多字符集
+ (NSCharacterSet *)controlCharacterSet;
+ (NSCharacterSet *)whitespaceCharacterSet;
+ (NSCharacterSet *)whitespaceAndNewlineCharacterSet;
+ (NSCharacterSet *)decimalDigitCharacterSet;
+ (NSCharacterSet *)letterCharacterSet;
+ (NSCharacterSet *)lowercaseLetterCharacterSet;
+ (NSCharacterSet *)uppercaseLetterCharacterSet;
+ (NSCharacterSet *)nonBaseCharacterSet;
+ (NSCharacterSet *)alphanumericCharacterSet;
+ (NSCharacterSet *)decomposableCharacterSet;
+ (NSCharacterSet *)illegalCharacterSet;
+ (NSCharacterSet *)punctuationCharacterSet;
+ (NSCharacterSet *)capitalizedLetterCharacterSet;
+ (NSCharacterSet *)symbolCharacterSet;
+ (NSCharacterSet *)newlineCharacterSet NS_AVAILABLE(10_5, 2_0);
3.替换字符串
NSString *strUrl = [[arr jsonStringEncoded] stringByReplacingOccurrencesOfString:@"\\" withString:@""];//去掉\