-1

Possible Duplicate:
how can I convert string to an array with separator?

Suppose:

string = @"Abc, Def, Ghi, Lmno";

I want those words, which are separated by comma, in an Array like this:

element 0 = Abc,

element 1 = Def,

element 2 = Ghi,

element 3 = Lmno.

2
  • u can search this link for more help stackoverflow.com/questions/6111543/… Commented Apr 20, 2012 at 9:25
  • 2
    Please make use of the Stack Overflow SEARCH function before asking questions that have been asked many many times. Commented Apr 20, 2012 at 9:37

5 Answers 5

9
NSArray *myArray = [myString componentsSeparatedByString:@","];

[myArray objectAtIndex:0];//Abc
[myArray objectAtIndex:1];//Def
[myArray objectAtIndex:2];//Ghi
[myArray objectAtIndex:3];//Lmno
Sign up to request clarification or add additional context in comments.

Comments

4

Try this code out:

NSArray *words = [string componentsSeparatedByString:@","];

Hope this helps.

Comments

2
yourstring = @"Abc, Def, Ghi, Lmno";
NSArray *array = [yourstring componentsSeparatedByString:@","];

Nslog (@"%@",array);

Comments

0
`NSString *str = @"This, is, test, string";
NSArray *myArray= [[NSArray alloc]initWithObjects:[NSString stringWithFormat:@"%@",str ], nil];
NSLog(@"%@", myArray);`

Comments

0

i would like to use componentsSeparatedByString. these kinds of methods are easily found in apple documentation

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.