有没有人能帮我回答下面这个问题?如果用户在UITextView中编写项目符号文本(多个换行符),如何检测换行符总数?
字符\n (换行符)未出现在UITextView的内容中。
发布于 2016-01-22 08:11:23
拉斐尔·奥利维拉的回答这不是理想的答案。
我找到了!
神奇的换行字符是\\ n。
代码是:
NSString *string = [object valueForKey:@"textViewContent"];
NSError *error = nil;
NSRegularExpression *regularExpression =
[NSRegularExpression regularExpressionWithPattern:@"\\n"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSUInteger numberOfMatches = [regularExpression numberOfMatchesInString:string
options:0
range:NSMakeRange(0,[string length])];
NSLog(@"%lu",(unsigned long)numberOfMatches);
NSUInteger lines = numberOfMatches;https://stackoverflow.com/questions/34936161
复制相似问题