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 8991965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:50:51+00:00 2026-06-15T22:50:51+00:00

My intent is to analyze the user’s input from a text field and check

  • 0

My intent is to analyze the user’s input from a text field and check if he used any symbols.

For example, user’s input is “/ardv/*k” and I need a variable that says the user typed 3 symbols.

I do not understand how to use NSRange to search against a string, because it stops as soon as it finds the first occurrence.

Also, NSSet is not compatible with characterAtIndex selector.

isEqualTo: didn’t work.

Here’s what I did, but I want to know how I can make this code simpler if possible:

  ...
    NSString *testThisString = @"/ardv/*k";        
    NSCharacterSet *unknownFlags1 = [NSCharacterSet punctuationCharacterSet];
    NSCharacterSet *unknownFlags2 = [NSCharacterSet symbolCharacterSet];
    NSCharacterSet *unknownFlags3 = [NSCharacterSet whitespaceCharacterSet];

    int count = 0;
    for (int i = 0; i < [testThisString length]; i++) {
    if ([unknownFlags1 characterIsMember:[testThisString characterAtIndex:i]] |
   [unknownFlags2 characterIsMember:[testThisString characterAtIndex:i]] | 
   [unknownFlags3 characterIsMember:[testThisString characterAtIndex:i]]) {
        count++;
    }
}
    NSLog(@"There are %d unknowns", count);
  ...
  • 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-15T22:50:53+00:00Added an answer on June 15, 2026 at 10:50 pm

    To check if a string has any characters belonging to a set, you simply do this:

    NSString *testString = @"hello$%^";
    NSRange r = [testString rangeOfCharacterFromSet:[NSCharacterSet punctuationCharacterSet]];
    if (r.location != NSNotFound) {
        // the string contains a punctuation character
    }
    

    If you want to know all of the locations of the punctuation characters, just keep searching with a different input range. Something like:

    NSRange searchRange = NSMakeRange(0, [testString length]);
    while (searchRange.location != NSNotFound) {
        NSRange foundRange = [searchString rangeOrCharacterFromSet:[NSCharacterSet punctuationCharacterSet] options:0 range:searchRange];
        searchRange.location = foundRange.location + 1;
        searchRange.length = [testString length] - searchRange.location;
        if (foundRange.location != NSNotFound) {
            // found a character at foundRange.location
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType(video/3gpp); intent.putExtra(Intent.EXTRA_STREAM, videoURI); startActivity(Intent.createChooser(intent,Upload video via:)); I used
Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/html"); intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com"); intent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
Possible Duplicate: Intent for editing plain text file with the installed file editor (if
I have and Intent and I pass, from the MainActivity, two ArrayLists of Parcelables
I am attempting to complete a browser plugin that will analyze text and mark
Background/Intent: So I'm going to create an event tracker from scratch and have a
My intent is to create a QTextEdit with its reach text controls. The controls
My intent is to create a library/API for small scale distributed multi-user game /simulation.
I'm using an Intent with ACTION_SEND and I need to share different texts. I
I want to sent intent from one first activity to another. The first activity

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.