csv文件,请帮助.... [英] csv file please help....

查看:91
本文介绍了csv文件,请帮助....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要删除csv(逗号分隔的值)中的一行
但我找不到方法...
我所发现的就是如何在没有逗号的情况下显示记录.

希望任何人都可以提供帮助....

谢谢...

I want to delete a line in csv(comma separated values)
but I cant find how to do it...
All I find is how to display the records of course without the comma...

Hope anyone can help....

Thanks...

推荐答案

CSV文件不是类似于数据库的结构化文件.因此,删除"行实际上涉及到复制所有行,直到要删除的行,然后跳过该行,然后写入文件的其余部分.
请注意,您会找到用于csv文件的数据库ODBC驱动程序,通过它可以删除"完整的行,但实际上,它们只是重写了文件.

请注意,在给定当前内存大小的情况下,最好将整个文件加载到链表中,在链表中的内存中进行所有操作,然后写出新文件...
A CSV file is not a structured file like a database. So ''deleting'' a line really involves copying all the lines, up to the line you want to delete, skipping that line, and writing the rest of the file.
Note that you''ll find database ODBC drivers for csv files, which let you ''delete'' complete rows, but under the hood, they''ll just re-write the file.

Note that, given current memory sizes, you''ll be better off loading the entire file in a linked list, doing all your operations in memory on the linked list, and then writing out your new file...


是的,我不是使用python和java之类的其他语言,但是在C语言中,它是如此难以覆盖现有文件,因为您必须阅读该文件并同时在其上附加行

样品...

Yeah I do not in other language like python and java but in C its so hard to overwrite the existing file because you must read it and same time append line to it

Sample...

File *file1;
file1 = fopen("data.csv","r");



不关闭file1我无法创建...



without closing the file1 I cannot create...

File *file2;
file2 = fopen("data.csv","a+");



当我在不关闭file1的情况下执行上述代码时,就会发生错误.



when I do the above code without closing the file1 the error occur.


请不要按答案来写问题.是的,如果您的文件已经打开,则无法重新打开它.您需要读取数据,将其关闭,打开以进行写入和覆盖.
Please don''t push answer to write questions. Yes, if your file is already open, you can''t reopen it. You need to read the data, close it, open it for writing and overwrite it.


这篇关于csv文件,请帮助....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆