मैं शब्दमैं टेक्स्ट व्यू में शब्दों और चरित्र की कुल संख्या की गणना कैसे कर सकता हूं?
-(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;
}
और यहाँ की कुल संख्या की गणना करने के लिए निम्न कोड का उपयोग कर रहा कुल चरित्र
-(NSInteger) getTotalChars{
NSString *str =[_editor textInRange:[_editor textRangeWithRange:[self visibleRangeOfTextView:_editor]]];
NSLog(@"%@",str);
NSInteger charCount= [[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]length];
return charCount=charCount-1;
}
लेकिन जब मैं से अधिक दर्ज सही गिनती नहीं हो रही im के लिए कोड है दो लाइनें यह शब्द के रूप में नई लाइन लेता है ..
कृपया मदद करें !!! !!!
'myString = [myString stringByReplacingOccurrencesOfString: @" \ n "withString : @ ""]; ' –
यह एक सही उत्तर है ... – mindfreak
http://stackoverflow.com/questions/6171422/objective-c-nsstring-wordcount http://stackoverflow.com/questions/4724206/how-do-you-get-the-number-of-words-in- ए-nstextstorage-nsstring http://stackoverflow.com/questions/3975209/what-is-the-most- कुशल-way-to-count-number-of-word-in-nsstring-without-using बहुत सारे डुप्लिकेट। – doge