Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:49:12+00:00 2026-06-12T16:49:12+00:00

I am starting to learn how to code a mac application using Objective C.

  • 0

I am starting to learn how to code a mac application using Objective C. Right now I have a TextView filled up with text. Is there any way I can get the number of instances a specific word appearing in that textview.

I have read up on NSTextFinder Class but I can’t set my TextView as the client of the NSTextFinder and there is no sample code to help me along. Any help is appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:49:14+00:00Added an answer on June 12, 2026 at 4:49 pm

    I’m assuming that all you need to do is provide a standard Cocoa find bar capability for NSTextView in which case it’s just self.textView.usesFindBar = YES for the NSTextView in question. When the users presses COMMAND + F

    Perhaps you’re looking for a solution that doesn’t use the find UI – but then you wouldn’t be using NSTextFinder whose function is to serve as the find UI’s controller class… If you’re looking for a non-UI-based search and count mechanism then edit your question and we can try to respond.

    EDIT:

    If you just want to count the occurrences of a word in the NSTextView‘s then NSScanner is a solution. See example of NSScanner as word counter in action:

    #import <Foundation/Foundation.h>
    
    int main(int argc, char *argv[]) {
        NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
    
        NSString *sampleString = @"The dog ate my homework. Later, \
             the dog ate my lunch.  Sometimes, dogs do that.";
        NSScanner *scanner = [NSScanner scannerWithString:sampleString];
        NSString *aDog = nil;
        NSInteger wordCount = 0;
        while( ![scanner isAtEnd] ) {
            if( [scanner scanUpToString:@"dog" intoString:&aDog] ) {
                if( [scanner scanString:@"dog" intoString:&aDog] ) {
                    wordCount++;
                }
            }
        }
        printf("There are %ld dog words in the text.\n",wordCount);
        [p release];
    }
    

    This prints out:

    There are 3 dog words in the text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting right from the beginning with Ruby to learn the ropes but have
im just starting to learn about sockets and i have been given this code,
I'm just starting to learn Objective-C using GNUstep on Windows and I'm wondering what
I'm a newbie starting to learn Ruby. I have created this code, however it
Starting to learn Canvas and have two classes so far (main one to call
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
I'm starting to learn Haskell and I've heard that many Haskell compilers have especially
I am just starting to learn how to use RMI, and I have a
I'm just starting to learn AspectJ, and I have use-case for say, User login.
I am just starting to learn about the code contracts library that comes standard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.