Kaibin
Kaibin

Reputation: 474

iOS NSMutableString split like java's String method split()

I hava a NSString which uses $ as delimiters, e.g.

    NSMutableString *str = @"AA$BB$CC";

So, my questio is: is there a method to split that NSMutableString by delimiters '$' and store into an array, just like in java:

    String[] list = str.split()

thanks advancde.

Upvotes: 1

Views: 1068

Answers (2)

giorashc
giorashc

Reputation: 13713

NSArray* splittedArray= [str componentsSeparatedByString:@"$"];
for (NSString *component in splittedArray) {
  NSLog(@"%@", component);
}

Upvotes: 5

Abdullah Md. Zubair
Abdullah Md. Zubair

Reputation: 3324

Yes. you can use componentsSeparatedByString method which works similar to split() method. Example:NSArray* list= [str componentsSeparatedByString:@"$"];

Upvotes: 1

Related Questions