Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-08-2009, 01:39 PM   #6 (permalink)
XCHG
Registered Member
 
Join Date: Nov 2008
Posts: 98
XCHG is on a distinguished road
Default

Quote:
Originally Posted by AndrewSpeaksOut View Post
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:@"_"];
There must be a better way of doing this. I need a very efficient way.

You can do it this way which is much more efficient:

Code:
NSString *Source = @"Bla1;' Bla2#^ Bla3";
  NSCharacterSet *AcceptedCharacterSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
  Source = [[Source componentsSeparatedByCharactersInSet:AcceptedCharacterSet] componentsJoinedByString:@" "];
  NSArray *Words = [Source componentsSeparatedByString:@" "];
  int WordCounter = 0;
  for (WordCounter = 0; WordCounter < [Words count]; WordCounter++){
    NSLog(@"%@", [Words objectAtIndex:WordCounter]);
  }
This outputs:

Bla1
Bla2
Bla3
__________________
UK Flights
Latest UK Flight information right in your iPhone/iPod Touch. All major UK Airports are available in this brilliant iPhone Application. Download from the iTunes Store.

GuitarMonster: Overdrive
A guitar plugged to an overdrive effect, right in your pocket. Download from the iTunes Store.
XCHG is offline   Reply With Quote
 

» Advertisements
» Online Users: 595
13 members and 582 guests
haisergeant, Hassasin, hdeuwere, matt2009, Paul Slocum, Rudy, skiril, skrew88, SLIC, Sophie100, st02197, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,319
Threads: 93,988
Posts: 402,409
Top Poster: BrianSlick (7,978)
Welcome to our newest member, st02197
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:28 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.