Split CSV/TXT file
void Main()
{
var path = @"c:\sourceGit\speciesLatLon.txt";
var inputLines = File.ReadAllLines(path);
// Holds all the lines to be added to each output file
var linesForCurrentSpeciesFile = new List<string>();
// Read first row
int i = 0;
var currentSpecies = GetSpecies(inputLines[i]);
// initialize hold value
var holdValue = currentSpecies;
// Initialize output values
linesForCurrentSpeciesFile.Add(inputLines[i]);
// Read next value
i++;
while( i < inputLines.Length )
{
currentSpecies = GetSpecies(inputLines[i]);
if (currentSpecies != holdValue)
{
// output current file
WriteSpeciesFile(holdValue, linesForCurrentSpeciesFile);
// Initialize new output file by clearing out the previous
linesForCurrentSpeciesFile.Clear();
// update hold value with the value just examined.
holdValue = currentSpecies;
}
// Add the current line to the output file
linesForCurrentSpeciesFile.Add(inputLines[i]);
i++;
}
// Write the output file because last row is equal to a break in the sequence
WriteSpeciesFile(currentSpecies, linesForCurrentSpeciesFile);
}
// Define other methods and classes here
public string GetSpecies(string line)
{
// return the first value of the input line
return line.Split(new char[] {','})[0];
}
public void WriteSpeciesFile(string species, List<string> content)
{
File.WriteAllLines(string.Format(@"C:\sourceGit\{0}.csv", species), content.ToArray());
}
Split CSV/TXT file的更多相关文章
- csv,txt,excel文件之间的转换,perl脚本
最近接触一些需要csv,txt,excel文件之间的转换,根据一些网上搜索加上自己的改动,实现自己想要的结果为主要目的,代码的出处已经找不到了,还请见谅,以下主要是针对csv&excel 和t ...
- js读取文本内容,支持csv.txt
js读取文本内容,支持csv.txt <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- (qsf文件 、 tcl文件 和 csv(txt)文件的区别) FPGA管脚分配文件保存、导入导出方法
FPGA管脚分配文件保存方法 使用别人的工程时,有时找不到他的管脚文件,但可以把他已经绑定好的管脚保存下来,输出到文件里. 方法一: 查看引脚绑定情况,quartus -> assignment ...
- 如何处理大体积 XLSX/CSV/TXT 文件?
在开发过程中,可能会遇到这样的需求,我们需要从本地的 Excel 或 CSV 等文件中解析出信息,这些信息可能是考勤打卡记录,可能是日历信息,也可能是近期账单流水.但是它们共同的特点是数据多且繁杂,人 ...
- python读取与写入csv,txt格式文件
python读取与写入csv,txt格式文件 在数据分析中经常需要从csv格式的文件中存取数据以及将数据写书到csv文件中.将csv文件中的数据直接读取为dict类型和DataFrame是非常方便也很 ...
- Java关于读取Excel文件~xlsx xls csv txt 格式文件~持续汇总~
所需的jar百度网盘链接:https://pan.baidu.com/s/146mrCImkZVvi1CJ5KoiEhQ提取码:c329 1 需要导入jar包,缺1不可 dom4j-1.6.1.jar ...
- python导入csv/txt文件
1. 导入csv文件 ### python导入csv文件的三种方法 ```python #原始的方式 lines = [line.split(',') for line in open('iris.c ...
- R—读取数据(导入csv,txt,excel文件)
导入CSV.TXT文件 read.table函数:read.table函数以数据框的格式读入数据,所以适合读取混合模式的数据,但是要求每列的数据数据类型相同. read.table读取数据非常方便,通 ...
- 【Python】通过python代码实现demo_test环境的登录,通过csv/txt/excel文件批量添加课程并开启课程操作--(刚开始 项目 页面 模块 元素这种鸟 被称作pageobject 等这些搞完 然后把你的定位器、数据 和脚本在分离 就是传说中那个叫数据驱动 的鸟)
一.1.通过csv文件批量导入数据 1 from selenium import webdriver from time import ctime,sleep import csv #循环读取每一行每 ...
随机推荐
- win10 uwp 读取resw资源文件
ResourceContext resourceContext = ResourceContext.GetForViewIndependentUse(); ResourceMap resourceMa ...
- maya_help()验证编程过程中模块导入的情况
import rigLib reload(rigLib.base.control)spine = rigLib.base.control.Control( prefix = 'spine1') hel ...
- vue cli 3.x的history 和 hash模式切换的问题
使用vue cli 3.x 创建的项目,有一个选项:Use history mode for router? (Requires proper server setup for index fallb ...
- Day 22 初识面向对象
一.两种编程思想 1.面向过程编程 核心是'过程',过程指的是解决问题的步骤,就是先干什么再干什么 基于面向过程思想编写程序相当于写一条流水线,是一种机械式的思维方式 优点:解决问题的思路清晰,可以把 ...
- @cacheevict 清除多个key
@Caching(evict={@CacheEvict(“a1”),@CacheEvict(“a2”,allEntries=true)}): 参考:https://www.cnblogs.com/ha ...
- STM32 USB-三个HID-interface 复合(组合)设备的代码实现-基于固件库(原创)
一.概论: 在STM32_USB-FS-Device_Lib_V4.1.0的Custom_HID工程基础上进行修改: 开发一款设备,有三个HID接口,mouse+pen+自定义HID 其中:0_HID ...
- Open Source 开发工具集
Open Source 开发工具集 转自:http://www.linuxforum.net原作者:gogoliu(Pooh-Bah) 编辑器: vi:老牌编辑器,在各个unix和unix-like平 ...
- keepalived+mysql主从环境,keepalived返回值是RST,需求解决方法?
环境描述: mysql版本5.6.37 keepalived-1.2.19 系统centos 7:3.10.0-514.26.2.el7 web是:windows server 2 ...
- Windows下安装Spark环境
根据博客总结 https://blog.csdn.net/nxw_tsp/article/details/78281533 需要的安装软件可以在网盘下载: 链接:https://pan.baidu.c ...
- django orm 管理器 objects
给某张表的管理器重命名 class User(models.Model): name = models.CharField(max_length=100) people = models.Manage ...