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.
You should use a regular expression:
EDIT To get the tags without the hash character
#, you should use a capturing group in the regex like the following:EDIT To get a string that contains the input string except the tags, you can use the following method:
Edit Now that you have the different tags, you can create a string that contains them like this: