I'm trying to take the text typed or pasted into a searchbar and remove all punctuation and separate each individual word and place it in an array. This is as close as I've gotten but there are a lot of empty entries in the array where the punctuation was.
Code:
NSString *sourceData = source.text;
NSString *filteredData = [[sourceData componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@"_"];
NSArray *components = [filteredData componentsSeparatedByString:@"_"];
Code:
S,
"",
history,
"",
affecting,
"",
"",
"",
states,
over,
an,
area,
of,
"",
"",
There must be a better way of doing this. I need a very efficient way.