2

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.

Abizern
  • 146,289
  • 39
  • 203
  • 257
Questions
  • 20,055
  • 29
  • 72
  • 101

2 Answers2

2

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

Abizern
  • 146,289
  • 39
  • 203
  • 257
2

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
  • 77,323
  • 27
  • 116
  • 141