此代码确定String是否包含空格和换行符:
- (BOOL)isNoBlack {
NSCharacterSet* charSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
for (int i = 0; i < self.length ; i++) {
unichar ch = [self characterAtIndex:i];
NSLog(@"%ld",ch);
if ([charSet characterIsMember:ch]) {
return NO;
}
}
return YES;
}
NSString* aStr = @"";
[aStr isNoBlack];
2018-03-01 09:13:05.443731 + 0800 CustomWindow [1630:110292] 55357
2018-03-01 09:13:05.443864 + 0800 CustomWindow [1630:110292] 56898
我的问题是,表情符号是否可以编码两个数字,一个存在空格或换行符,因此这种方法不起作用。