考虑将特殊字符放入 .csv 文件中
我正在开发应用程序,在其中我必须考虑所有特殊字符。我正在使用下面的代码,但在其中我也想考虑“空格和逗号”,但在其中,当触发空格时,它会在该位置分割并创建新的字段为它..所以朋友们有没有考虑特殊字符的解决方案。如果您有任何想法,请建议我。谢谢
arrCsv=[[NSArray alloc]initWithObjects:@"Hello",@"Hi",@"traun testdata",@"Hi,fine",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/try.csv", documentsDirectory];
[[arrCsv componentsJoinedByString:@","] writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:NULL];
I am working on application, in it I have to consider all special characters.I am using below code but in it I also want to consider "space and comma" but in it, when trigger space it make split at that place and make new fild for it..so friends is there any solutions to consider special characters.If you have any idea then please suggest me.Thanks
arrCsv=[[NSArray alloc]initWithObjects:@"Hello",@"Hi",@"traun testdata",@"Hi,fine",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/try.csv", documentsDirectory];
[[arrCsv componentsJoinedByString:@","] writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:NULL];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以简单的方式编写您自己的 CSV 解析例程既容易出错,又会浪费不必要的时间。我强烈建议您使用 Dave DeLong 优秀的 CHCSV 库。
如果您想使用此库,您可以按照以下方式执行操作以将两行写入文件:
Writing your own CSV parsing routines in a simplistic fashion is both error-prone and needlessly time-consuming. I highly recommend you use Dave DeLong's excellent CHCSV library.
If you wanted to use this library, you could do something along the following lines to write two rows to a file: