从C#中的.DAT文件读取特定行 [英] reading particular lines from a .DAT file in C#

查看:171
本文介绍了从C#中的.DAT文件读取特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在C#中做一个程序,其中有.DAT文件,该文件包含以下数据

标题:BHEL-200W
评论:BHEL-EDN
操作:管理员
ID:A112436
模组类型:L20200
案卷号:00000001
日期:2010年6月26日
时间:09:06:31
辐照度:99.5071
更正为:100
模块温度:23.3882
更正为:23.3882
RCCC:1.4970
频道:1
挥发性有机化合物:37.3490
Isc:8.49912
R系列:0.62710
Rshunt:68.2882
Pmax:230.793
Vpm:29.8042
Ipm:7.74365
填充因子:0.72705
实际有效:15.8060
Appff效果:14.0153
区域:243.36
Ser中的段:60
段中的段数:1
面板面积:16467.2
负载:27.33
Ivld:7.98577
编号:218.247
电压:电流:
0.0000000 8.5035150
0.0146520 8.5007290


从那里我只需要阅读以下行

ID:A112436
模组类型:L20200
案卷号:00000001
挥发性有机化合物:37.3490
Isc:8.49912

请帮我怎么做
感谢All

Hi All,
I am doing a program in C# where I have .DAT file which have the following data

Title: BHEL-200W
Comment: BHEL-EDN
Op: Admin
ID: A112436
Mod Type: L20200
Docket Num: 00000001
Date: 06/26/2010
Time: 09:06:31
Irradiance: 99.5071
Corrected To: 100
Module Temp: 23.3882
Corrected To: 23.3882
RCCC: 1.4970
Channel: 1
Voc: 37.3490
Isc: 8.49912
Rseries: 0.62710
Rshunt: 68.2882
Pmax: 230.793
Vpm: 29.8042
Ipm: 7.74365
Fill Factor: 0.72705
Active Eff: 15.8060
Appature Eff: 14.0153
Segment Area: 243.36
Segs in Ser: 60
Segs in Par: 1
Panel Area: 16467.2
Vload: 27.33
Ivld: 7.98577
Pvld: 218.247
Voltage: Current:
0.0000000 8.5035150
0.0146520 8.5007290


from where I have to read only the following line

ID: A112436
Mod Type: L20200
Docket Num: 00000001
Voc: 37.3490
Isc: 8.49912

please help me how to do that
Thanks to All

推荐答案

您不能.您需要阅读整个文件,然后找到所需的数据.您可以从头开始阅读,但不能只选择一个点,特别是在您知道哪一行而不是要读取哪个字节的情况下.
You can''t. You need to read the whole file, then find the data you want. You can read from the start to that point, but you can''t just choose a point, especially in a situation where you know what line, but not what byte to read.


使用类System.IO.StreamReader.使用方法System.IO.StreamReader.ReadLine逐行读取,并在读取时动态分析每一行;如果该行包含不相关的数据,则将其忽略.

如果这对您不方便,请使用System.IO.StreamReader.ReadToEnd将所有内容读取到单个字符串中,然后再提取所需的数据.在这种情况下:

Use the class System.IO.StreamReader. Read line by line using the method System.IO.StreamReader.ReadLine and analyze each line on the fly as you read; if the line contains irrelevant data just ignore it.

If this is inconvenient for you, read everything into a single string using System.IO.StreamReader.ReadToEnd and extract required data later. In this case:

string allData = //... got via System.IO.StreamReader.ReadToEnd
string[] lines = allData.Split(
    new string[] { System.Environment.NewLine });



在这种情况下,您将能够按已知的行数索引数组.

—SA



In this case you will be able to index the array by known number of line.

—SA


这篇关于从C#中的.DAT文件读取特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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