views:

23

answers:

2

Hi, everyone,

I have a question about the objective C. I have the following NSString *name shown below:

 "First Name","Second Name","Last Name";

Actually, name is the header of the CSV and receive from the URL. And I use the follow statement to break the statement to array.

NSMutableArray *csvTitleArray;
csvTitleArray = [[name componentsSeparatedByString:@","];

The result of the array is

[0] = "First Name"     // the " is part of the string, it means the first char of [0] is ", not F
[1] = "Second Name"
[2] = "Last Name"

However, I want to cancel the " in the begin and end of the string (the " is part of the string. Can anyone help me? Thank you.

+2  A: 

Have you thought of using stringByReplacingOccurrencesOfString:withString: and then splitting the string out into an array?

Abizern
+2  A: 

Have a look at parsing csv data, the General CSV section (code example) handles your case.

See writing parser using nsscanner - csv for usefull more generic pointers about parsing data.

stefanB