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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:50:50+00:00 2026-05-25T20:50:50+00:00

I have a search string, where people can use quotes to group phrases together,

  • 0

I have a search string, where people can use quotes to group phrases together, and mix this with individual keywords. For example, a string like this:

"Something amazing" rooster

I’d like to separate that into an NSArray, so that it would have Something amazing (without quotes) as one element, and rooster as the other.

Neither componentsSeparatedByString nor componentsSeparatedByCharactersInSet seem to fit the bill. Is there an easy way to do this, or should I just code it up myself?

  • 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-05-25T20:50:51+00:00Added an answer on May 25, 2026 at 8:50 pm

    I ended up going with a regular expression as I was already using RegexKitLite, and creating this NSString+SearchExtensions category.

    .h:

    //  NSString+SearchExtensions.h
    #import <Foundation/Foundation.h>
    @interface NSString (SearchExtensions)
    -(NSArray *)searchParts;
    @end
    

    .m:

    //  NSString+SearchExtensions.m
    #import "NSString+SearchExtensions.h"
    #import "RegexKitLite.h"
    
    @implementation NSString (SearchExtensions)
    
    -(NSArray *)searchParts {
        __block NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:5];
    
        [self enumerateStringsMatchedByRegex:@"\\w+|\"[\\w\\s]*\"" usingBlock: ^(NSInteger captureCount,
           NSString * const capturedStrings[captureCount],
           const NSRange capturedRanges[captureCount],
           volatile BOOL * const stop) {
    
            NSString *result = [capturedStrings[0] stringByReplacingOccurrencesOfRegex:@"\"" withString:@""];
    
            NSLog(@"Match: '%@'", result);
            [items addObject:result];
        }];        
        return [items autorelease];
    }
    @end
    

    This returns an NSArray of strings with the search strings, removing the double quotes that surround the phrases.

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

Sidebar

Related Questions

I have a requirement to search for people by name. Here peoples' names can
I have the following controller: public ActionResult Search(string Name, int? Friend, int? Page) It
I have a search method that takes in a user-entered string, splits it at
I have a folder full of files and I want to search some string
I have input.txt and I want to search for a string and extract a
I have a NSMutableArray that I need to search for a string and return
I have a string s and I want to search for the substring of
I have a string of letters and I want to search it for a
i have a text file with string abcdef I want to search for the
I have an active directory search function: Function GetAdInfo(ByVal ADDN As String, ByVal ADCommonName

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.