一个程序php生成csv文件的csv文件,如何查看是否被修改过?

csv文件查看器(CSVFileView)下载 v2.0.1绿色版_csv文件查看软件 - pc6下载站I have a csv file containing 15,00,000 records and need to find the duplicate rows from the csv file. I am trying as below code
DataTable dtUniqueDataView = dvDataView.ToTable(true, Utility.GetHeadersFromCsv(csvfilePath).Select(c =& c.Trim()).ToArray());
But in this I am not getting the duplicate records and it is taking nearly 4 mins time to do the operation. Can any one suggest the process which could reduce the time and give the duplicate result set.
解决方案 I wrote an example with Hashset:
Output (15,000,000 entries in a csv file):
Reading File
File distinct read in
Output (30,000,000 entries in a csv file):
Reading File
File distinct read in
Output (45,000,000 entries in a csv file):
Reading File
File distinct read in
class Program
static void Main(string[] args)
string csvFile = "test.csv";
if (!File.Exists(csvFile)) //Create a test CSV file
CreateCSVFile(csvFile, 000);
List&string& distinct = GetDistinct(csvFile); //Returns every line once
Console.ReadKey();
static List&string& GetDistinct(string filename)
Stopwatch sw = new Stopwatch();//just a timer
List&HashSet&string&& lines = new List&HashSet&string&&(); //Hashset is very fast in searching duplicates
HashSet&string& current = new HashSet&string&(); //This hashset is used at the moment
lines.Add(current); //Add the current Hashset to a list of hashsets
sw.Restart(); //just a timer
Console.WriteLine("Reading File"); //just an output message
foreach (string line in File.ReadLines(filename))
if (lines.TrueForAll(hSet =& !hSet.Contains(line))) //Look for an existing entry in one of the hashsets
current.Add(line); //If line not found, at the line to the current hashset
catch (OutOfMemoryException ex) //Hashset throws an Exception by ca 12,000,000 elements
current = new HashSet&string&() { line }; //The line could not added before, add the line to the new hashset
lines.Add(current); //add the current hashset to the List of hashsets
sw.Stop();//just a timer
Console.WriteLine("File distinct read in " + sw.Elapsed.TotalMilliseconds + " ms");//just an output message
List&string& concatinated = new List&string&(); //Create a list of strings out of the hashset list
lines.ForEach(set =& concatinated.AddRange(set)); //Fill the list of strings
//Return the list
static void CreateCSVFile(string filename, int entries, int duplicateRow)
StringBuilder sb = new StringBuilder();
using (FileStream fs = File.OpenWrite(filename))
using (StreamWriter sw = new StreamWriter(fs))
Random r = new Random();
string duplicateLine =
string line = "";
for (int i = 0; i & i++)
line = r.Next(1, 10) + ";" + r.Next(11, 45) + ";" + r.Next(20, 500) + ";" + r.Next(2, 11) + ";" + r.Next(12, 46) + ";" + r.Next(21, 501);
sw.WriteLine(line);
if (i % duplicateRow == 0)
if (duplicateLine != null && i & entries - 1)
sb.AppendLine(duplicateLine);
duplicateLine =
本文地址: &
我有一个包含15,00,000记录的csv文件,并需要找到CSV文件中重复的行。我想,如下code
的DataTable dtUniqueDataView = dvDataView.ToTable(真,Utility.GetHeadersFromCsv(csvfilePath)。选择(C => c.Trim())ToArray的()); 但在这我没有得到重复的记录,它正在采取近40分钟的时间做了手术。任何一个可以表明它可以减少时间,让重复的结果集的过程。解决方案 我写了HashSet的例子:输出(在一个csv文件项):读文件文件不同的读在毫秒 输出(在一个csv文件项):读文件文件不同的读在毫秒 输出(在一个csv文件项):读文件文件不同的读在毫秒
静态无效的主要(字串[] args)
字符串csvFile =“test.csv”;
如果(!File.Exists(csvFile))//创建一个测试CSV文件
CreateCSVFile(csvFile,);
清单<串GT;不同= GetDistinct(csvFile); //返回每行一次
Console.ReadKey();
静态列表<串GT; GetDistinct(字符串文件名)
秒表SW =新秒表(); //只是一个计时器
清单<&HashSet的LT;串GT;>行=新的List<&HashSet的LT;串GT;>();的Hashset //在重复搜索速度非常快
HashSet的<串GT;电流=新的HashSet<串GT;(); //这是HashSet的目前使用
lines.Add(电流); //当前的Hashset添加到hashsets列表
sw.Restart(); //只是一个计时器
Console.WriteLine(“读文件”); //只是输出消息
的foreach(在File.ReadLines串线(文件名))
如果(lines.TrueForAll(HSET =>!hSet.Contains(线)))//在hashsets之一查找现有条目
current.Add(线); //如果未找到行,在该行对当前的HashSet
赶上(OutOfMemoryException异常前)//通过的Hashset CA抛出Exception 元
电流=新的HashSet<串GT;(){}行; //行无法前加入,该行添加到新的HashSet
lines.Add(电流); //当前HashSet的增加hashsets的列表
sw.Stop(); //只是一个计时器
Console.WriteLine(“文件在不同的读”+ sw.Elapsed.TotalMilliseconds +“毫秒”); //只是一个输出消息
清单<串GT;串连=新的List<串GT;(); //创建一个字符串列表出来的HashSet的名单
lines.ForEach(套=> concatinated.AddRange(套)); //填充字符串列表
返回串连; //返回列表
静态无效CreateCSVFile(字符串的文件名,诠释作品,诠释duplicateRow)
StringBuilder的SB =新的StringBuilder();
使用(的FileStream FS = File.OpenWrite(文件名))
使用(StreamWriter的SW =新的StreamWriter(FS))
随机R =新的随机();
字符串duplicateLine = NULL;
串线=“”;
的for(int i = 0; I<条目;我++)
线= r.Next(1,10)+“;” + r.Next(11,45)+“;” + r.Next(20,500)+“;” + r.Next(2,11)+“;” + r.Next(12,46)+“;” + r.Next(21,501);
sw.WriteLine(线);
如果(I%duplicateRow == 0)
如果(duplicateLine = NULL&放大器;&安培; I<!条目 -
sb.AppendLine(duplicateLine);
duplicateLine =行;
本文地址: &
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起
(window.slotbydup = window.slotbydup || []).push({
id: '5828425',
container: s,
size: '300,250',
display: 'inlay-fix'怎么查看CSV文件的编码? 就是说,现在又个CSV文件,里面的文字没有乱码,但是跑到程序里面就乱码了_百度知道
怎么查看CSV文件的编码? 就是说,现在又个CSV文件,里面的文字没有乱码,但是跑到程序里面就乱码了
怎么查看乱码的文字,是什么编码???CSV文件...
怎么查看乱码的文字,是什么编码???CSV文件
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
采纳数:134
获赞数:397
UltraEdit-32软件打开,在底部状态栏有标识:U=U U8-DOS=UTF-8; DOS=ANSI;
为你推荐:
其他类似问题
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。基础知识,用程序读取CSV文件的方法
招聘信息:
CSV全称 Comma Separated values,是一种用来存储数据的纯文本文件格式,通常用于电子表格或数据库软件。用Excel或者Numbers都可以导出CSV格式的数据。
CSV文件的规则
0 开头是不留空,以行为单位。
1 可含或不含列名,含列名则居文件第一行。
2 一行数据不垮行,无空行。
3 以半角符号,作分隔符,列为空也要表达其存在。
4 列内容如存在,,则用“”包含起来。
5 列内容如存在“”则用“”“”包含。
6 文件读写时引号,逗号操作规则互逆。
7 内码格式不限,可为ASCII、Unicode或者其他。
用如下代码即可读取简单的CSV文件:
NSString *path = [[NSBundle mainBundle] pathForResource:@"ECG_Data" ofType:@"csv"];
NSString *contents = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *contentsArray = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
for (idx = <span style="color: #; idx < contentsArray. idx++) {
& & NSString* currentContent = [contentsArray objectAtIndex:idx];
& & NSArray* timeDataArr = [currentContent componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
另外,如果需要处理复杂的CSV文件,推荐使用代码库。
微信扫一扫
订阅每日移动开发及APP推广热点资讯公众号:CocoaChina
您还没有登录!请或
点击量1921点击量1795点击量1607点击量1542点击量1508点击量1472点击量1318点击量1304点击量1278
&2018 Chukong Technologies,Inc.
京公网安备89查看: 591|回复: 2
求助:2个csv文件做对比,删除相同项,在不影响文件结构的情况下,保存csv文件。
阅读权限30
在线时间 小时
有2个CSV文件,一个是原文件,一个是要删除的文件。
现在想在不损失文件结构的前提下从原文件中剔除要删除的文件里面的数据。
由于最终的结果数据要导回系统,所以不能在EXCEL中直接操作。
有人说可以通过二进制的方式处理,小弟不得要领,特来求助。
(8.46 KB, 下载次数: 4)
09:54 上传
点击文件名下载附件
(41.3 KB, 下载次数: 4)
09:54 上传
点击文件名下载附件
阅读权限30
在线时间 小时
判断两个文件数据是否相同的条件,是两个文件第一列的数据。即宝贝名称
阅读权限30
在线时间 小时
已解决(OK)。
最新热点 /1
本活动是由微软(中国)有限公司发起,申请通过者可以得到Office 365企业级E3 试用账号,并享有全套Office 365客户端及云端高效、协作办公体验。 机会有限,先到先得!
玩命加载中,请稍候
玩命加载中,请稍候
Powered by
本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任! & & 本站特聘法律顾问:徐怀玉律师 李志群律师}

我要回帖

更多关于 php生成csv文件 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信