2011-03-02 70 views

回答

1

你已经看过this stack overflow的问题吗?

+0

是的,但我不想送contents.I的数组要从我的数据库发送一个表。 – Warrior 2011-03-02 13:25:38

+1

好战士,你有一个选择。您可以将数据从数据库读取到标准的Objective-c集合对象(如NSArray)中,然后使用建议的解决方案,或者您可以永远等待某人为您发布一项微不足道的额外工作连接到您的数据库的CSV库。这是你的选择。 – occulus 2011-03-02 14:22:41

3

你应该看看Dave Delong制作的CHCSVParser。忽略名字,它也是一位作家。

它工作得很好;直到要支持德国(和其他人)csv格式,它使用分号

+0

如何给CHCSV写入器输入? – Warrior 2011-03-03 08:07:09

+0

为NSArray创建NSArray(对于列),然后可以使用NSArray + CHCSVAdditions.h中的NSArray类别方法'writeToCSVFile:atomically:'。但还有其他方法,请参阅CHCSVParser的自述文件 – 2011-03-03 08:19:18

1

嘿,我找到简单的代码::

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); 
     NSString *documentsDir = [paths objectAtIndex:0]; 
     NSString *root = [documentsDir stringByAppendingPathComponent:@"customers.csv"]; 

     NSString *temp; 

     temp = [NSString stringWithFormat:@"%@", [arrCustomersName objectAtIndex:0]]; 

     for (int i = 1; i < [arrCustomersName count]; i++) { 

      temp = [temp stringByAppendingFormat:@", %@", [arrCustomersName objectAtIndex:i]]; 
     } 

     [temp writeToFile:root atomically:YES encoding:NSUTF8StringEncoding error:NULL]; 
相关问题