iOS textview needs to wrap multiple lines like WeChat and only output once.
For example:
123
31
123
will eventually become:
123
31
123, is there any solution?
I wrote a loop but I can only remove the first one between 123 and 31, but there is nothing I can do about the rest
int x = 0 ;
for (int i = 0; i < _info.length; i ++) {
if ([[_info substringWithRange:NSMakeRange(i, 1)] isEqualToString:@"\n"]) {
x ++;
}
else{
if (x > 1) {
_info = [_info stringByReplacingCharactersInRange:NSMakeRange(i - x, x) withString:@"\n"];
x = 0;
}
}
}
还有一个小要求就是textview统计字数的时候把换行也算上,要加上一行能打出的字的数量,谢谢。