如何将一列文本文件复制到另一个文本文件 [英] How to copy one column of textfile to another textfile

查看:124
本文介绍了如何将一列文本文件复制到另一个文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我是一名专业的地球物理学家,并开始从http://www.codeproject.com在线学习Vb .net。我正在尝试阅读包含以下三列的文本文件:

IL19623 research_Project 2912394

IL19625 research_Project 2912425

IL19627 research_Project 2912425
IL19629 research_Project 2912450

IL19631 research_Project 2912450

IL19633 research_Project 2912477

IL19635 research_Project 2912477

IL19637 research_Project 2912504

IL19639 research_Project 2912504

IL19641 research_Project 2912521

IL19643 research_Project 2912521

IL19645 research_Project 2912542

IL19647 research_Project 2912542



每列与其他列以不同的间距分开。

我想将第一列复制到一个新的文本文件中,我想总结第三列以获得总计。在此先感谢您的帮助..

如果您能告诉一些有用的命令从一个文本文件到另一个文本文件进行数学计算,我将非常感激。

最好的问候

Syed Emad

Dear All,

I am a Geophysicist by profession and started to learn Vb .net online from http://www.codeproject.com. I am trying to read a text file with three columns as following:
IL19623 research_Project 2912394
IL19625 research_Project 2912425
IL19627 research_Project 2912425
IL19629 research_Project 2912450
IL19631 research_Project 2912450
IL19633 research_Project 2912477
IL19635 research_Project 2912477
IL19637 research_Project 2912504
IL19639 research_Project 2912504
IL19641 research_Project 2912521
IL19643 research_Project 2912521
IL19645 research_Project 2912542
IL19647 research_Project 2912542

Each column is seperated from other with different spacing.
I want to copy the first column to a new text file and i want to Sum the third column to get a total. Thanks in advance for the help..
I will highly appreciate if you could tell some useful commands to make mathematical calculations from one textfile to another.
Best regards
Syed Emad

推荐答案

如果您逐行阅读文件,那么您可以分开每行中的字段使用 String.Split [ ^ ]方法。然后,您可以将第一个字段写入新文件。您可以使用 Int32.TryParse <将第三个字段转换为整数值/ a> [ ^ ]方法。这将允许您对第三列求和。
If you read the file line by line then you can separate the fields in each line by using the String.Split[^] method. You can then write the first field out to a new file. You can convert the third field to an integer value with the Int32.TryParse[^] method. That will allow you to sum the third column.


这篇关于如何将一列文本文件复制到另一个文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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