How to convert NSString to an array?

For example, I read data such as

a\tbcd\tttte\tjjjd\tnjnjnjd\tss\tee

and I want to create an array like this:

{ @"a", @"bcd", @"ttte", @"jjjd", @"njnjnjd", @"ss", @"ee" }

How can i do this? Thank.

+3
source share
2 answers

You can use -componentsSeparatedByString:as in

NSArray *ary = [mystring componentsSeparatedByString:@"\t"];
+31
source
- (NSArray *)componentsSeparatedByString:(NSString *)separator 

componentsSeparatedByString: returns an array containing the substrings from the receiver that was split into this separator.

  • (NSArray *) componentsSeparatedByString: (NSString *) separator Separator parameter A separator string. Return Value An NSArray object containing substrings from the receiver, which was delimited by a delimiter.

, . . , , , , . , :

 NSString *list = @"Norman, Stanley, Fletcher";
 NSArray *listItems = [list componentsSeparatedByString:@", "];
produces an array { @"Norman",@"Stanley", @"Fletcher" }.

, , ", , , Fletcher" - : {@ ", @" ", @" ", @" "}

, ," Norman "- {@" Norman"}.

Mac OS X 10.0 .

. :

componentsJoinedByString: (NSArray)

- pathComponents

:

ColorMatching

CoreRecipes

iSpend

iSpendPlugin

QTKitMovieShuffler

NSString.h

NSString docs

+2

Source: https://habr.com/ru/post/1788131/


All Articles