-2

I want one sentence in NSString object like this:

NSString *myWords = @"Hi,I'm Janatan! I love objective C!!!";

I want split this sentence to more part for example :

first part : Hi

second part : I'm Janatan

third part : I love objective C

I want do this with loop but I don't know how to do it. I want split words until arrive to signs (! , ? . and etc)

please guide me about that.

user3599133
  • 155
  • 3
  • 17
  • `componentsSeparatedByCharactersInSet:`? Or replacing "special" characters with "characters+\n"? – Larme May 18 '14 at 10:31
  • If want to do in swift please check the below link [http://stackoverflow.com/questions/25678373/swift-split-a-string-into-an-array][1] [1]: http://stackoverflow.com/questions/25678373/swift-split-a-string-into-an-array – iPC May 05 '15 at 04:56

1 Answers1

2

You can do it with the componentsSeparatedByCharactersInSet, e.g.:

NSString *myWords = @"Hi,I'm Janatan! I love objective C!!!";
NSArray *arr = [str componentsSeparatedByCharactersInSet:
          [NSCharacterSet characterSetWithCharactersInString:@"!,"]];
sunshinejr
  • 4,834
  • 2
  • 22
  • 32