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

  • Home
  • SEARCH
  • 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 7845021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:05:15+00:00 2026-06-02T17:05:15+00:00

I don’t know how I should do this, I have tried using code like:

  • 0

I don’t know how I should do this, I have tried using code like:

NSString *stringToFind = @"Hi";
NSString *fullString = @"Hi Objective C!";
NSRange range = [fullString rangeOfString :stringToFind];
if (range.location != NSNotFound)
{
    NSLog(@"I found something.");
}

But it doesn’t fit my needs, I want to search for a string like #customstring (# means a tag) where the tag is specified by the user so they enter something like this Something #hello #world, what I want to do is search for all the # and the string attached to it and save it somewhere.

EDIT: The tag string created, I am saving that in a plist, but when I save it, it only saves one tag because I simply specified the string as tag. So like this:

[db addNewItem:label tagString:tag];

I need all of the tags created. For example in my logs:

I log tag, this comes up #tag,
I log tag again with two tags like this Something #hello #world I get two tags like this:#hello & #world each separate logs.

The result I want is this:

#hello, #world and then store it in a string and save it to my DB.

  • 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-02T17:05:18+00:00Added an answer on June 2, 2026 at 5:05 pm

    You should use a regular expression:

    NSString *input = @"Something #hello #world";
    
    NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"#\\w+" options:0 error:nil];
    NSArray *matches = [regex matchesInString:input options:0 range:NSMakeRange(0, input.length)];
    
    NSLog(@"%d matches found.", matches.count);
    for (NSTextCheckingResult *match in matches) {
        NSString *tag = [input substringWithRange:[match range]];
        NSLog(@"%@", tag);
    }
    // #hello
    // #world
    

    EDIT To get the tags without the hash character #, you should use a capturing group in the regex like the following:

    NSString *input = @"Something #hello #world";
    
    NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"#(\\w+)" options:0 error:nil];
    NSArray *matches = [regex matchesInString:input options:0 range:NSMakeRange(0, input.length)];
    
    NSLog(@"%d matches found.", matches.count);
    for (NSTextCheckingResult *match in matches) {
        NSString *tag = [input substringWithRange:[match rangeAtIndex:1]];
        NSLog(@"%@", tag);
    }
    // hello
    // world
    

    EDIT To get a string that contains the input string except the tags, you can use the following method:

    NSString *stringWithoutTags = [regex stringByReplacingMatchesInString:input options:0 range:NSMakeRange(0, input.length) withTemplate:@""];
    NSLog(@"%@", stringWithoutTags);
    // Something
    

    Edit Now that you have the different tags, you can create a string that contains them like this:

    NSMutableArray *tagsArray = [NSMutableArray array];
    for (NSTextCheckingResult *match in matches) {
        NSString *tag = [input substringWithRange:[match range]];
        [tagsArray addObject:tag];
    }
    NSString *tagsString = [tagsArray componentsJoinedByString:@", "];
    NSLog(@"tagsString: %@", tagsString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

don't know better title for this, but here's my code. I have class user
Don't know if this has been answered before. Have custom routes to users. If
I don't know if this has been asked before, but what i'd like to
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't know why but I can't find a solution to this. I have 3
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
Don't really know how to formulate the title, but it should be pretty obvious
I don't know whether this is really possible, but I'm trying my best. If
I don't know if this is a well known 'thing' or something new in
(Don't know if this is strictly on-topic, but I don't see any better Stack

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.