从文本文件中读取和连接5行并将其写入其他文本文件 [英] Reading and connecting 5 lines from text file and writing them to other text file

查看:126
本文介绍了从文本文件中读取和连接5行并将其写入其他文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何实现这样的事情:我有一个文本文件,其中包含每行中项目的信息,一行 - 项目标题,其他行 - 项目价格,第三行 - 项目描述... Totaly有5行每件商品,如果我有3件商品就会有15行。



我应该如何逐行阅读文件,每5行我可以写成其他文本文件中的一行?



文本文件的虚拟信息nr。 1:

联想上网本

356.00 $

SN4589 IoS

Black

快速电脑

联想22上网本

99.00 $

SN1233 IoS

白色

慢速计算机




程序操作后的第二个文本文件:

联想上网本356.00 $ SN4589 IoS黑色快速电脑

联想22上网本99.00 $ SN1233 IoS白色慢电脑




我正在阅读这些代码的行:

How should I implement such thing: I have a text file, which contains information about item in each line, one line - item title, other line - item price, third line - item description... Totaly there is 5 lines per items, and if I have 3 items there will be 15 lines.

How should I read the file line by line, that every 5 lines I could write them as one line in other text file?

Dummy info of text file nr. 1:
Lenovo netbook
356.00$
SN4589 IoS
Black
Fast computer
Lenovo 22 netbook
99.00$
SN1233 IoS
White
Slow computer


Second text file after program actions:
Lenovo netbook 356.00$ SN4589 IoS Black Fast computer
Lenovo 22 netbook 99.00$ SN1233 IoS White Slow computer


I am reading lines with such code:

System.Collections.Generic.IEnumerable<String> lines = File.ReadLines("c:\\file.txt")





如何获取行数(文件数)并且每5行作为一行写入新文件?



How to get number of lines array (file lines) and write every 5 lines as one line to new file?

推荐答案



SN4589 IoS

Black

快速电脑

联想22上网本

99.00

SN4589 IoS
Black
Fast computer
Lenovo 22 netbook
99.00




SN1233 IoS

白色

慢速电脑



程序操作后的第二个文本文件:

联想上网本356.00

SN1233 IoS
White
Slow computer


Second text file after program actions:
Lenovo netbook 356.00


SN4589 IoS黑色快速计算机

联想22上网本99.00
SN4589 IoS Black Fast computer
Lenovo 22 netbook 99.00


这篇关于从文本文件中读取和连接5行并将其写入其他文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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