używam następujący kod do obliczenia całkowitej liczby słówJak mogę obliczyć całkowitą liczbę słów i znaków w textView?
-(NSInteger) getTotalWords{
NSLog(@"Total Word %lu",[[_editor.attributedText string]length]);
if ([[_editor.attributedText string]length]==0) {
return 0;
}
NSString *str =[_editor textInRange:[_editor textRangeWithRange:[self visibleRangeOfTextView:_editor]]];
NSInteger sepWord = [[[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]componentsSeparatedByString:@" "] count];
sepWord += [[[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]componentsSeparatedByString:@"\n"] count];
sepWord=sepWord-2;
return sepWord;
}
i tu jest kod na łączną charakteru
-(NSInteger) getTotalChars{
NSString *str =[_editor textInRange:[_editor textRangeWithRange:[self visibleRangeOfTextView:_editor]]];
NSLog(@"%@",str);
NSInteger charCount= [[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]length];
return charCount=charCount-1;
}
ale im nie otrzymania idealnego count kiedy wprowadzić więcej niż dwie linie. nowa linia to słowo ...
prosze o pomoc .. !!!
'myString = [myString stringByReplacingOccurrencesOfString: @ "\ n" withString : @ ""]; ' –
to jest idealne ans ... – mindfreak
http://stackoverflow.com/questions/6171422/objective-c-nsstring-wordcount http://stackoverflow.com/questions/4724206/how-do-you-get-the-number-of-words-in- a-nstextstorage-nsstring http://stackoverflow.com/questions/3975209/what-is-the-most-efficient-way-to-count-number-of-word-in-nsstring-without-using Dużo duplikaty. – doge