How to split newline from NSString in ObjectiveC

后端 未结 1 1565
遇见更好的自我
遇见更好的自我 2021-01-05 03:44

For my new project. i have loaded my csv file content as a NSString. First, i need to split this by newline, then split each line by comma. How can i loop all this? Could y

1条回答
  •  我在风中等你
    2021-01-05 04:11

    Might want to look into NSMutableArray.

    // grab your file
    NSMutableArray *data = [[fileString componentsSeparatedByCharactersInSet: [NSCharacterSet newlineCharacterSet]] mutableCopy];
    for (int i = 0; i < [data count]; i++)
    {
        [data replaceObjectAtIndex: i
                        withObject: [[data objectAtIndex: i] componentsSeparatedByString: @","]];
    }
    

    Relatedly, Dave DeLong has a proper library to address this need: https://github.com/davedelong/CHCSVParser

    0 讨论(0)
提交回复
热议问题