在C#和.net中解析文本文件 [英] Parsing a Text file in C# and .net

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

问题描述

嗨..我想知道如何在Csharp.Net中解析文本文件.我举一个例子说明我的文本文件.
如何在数据表中提取此表中的内容(在文本文件中)?
这是我的文本文件的格式:

Hi..i want to know how can i parse a text file in Csharp.Net .I am giving an example of my textfile.
How can I extract the contents in this table (in text file ) in a datatable ?
This is the format of my textfile:

	ABC Firm Pvt Limited

	Product Catalog

Product ID	Product Name	Quantity Available
--------------------------------------------------
--------------------------------------------------
	1       PQR 			50
	2	XYZ			150
	3	EEF			15

推荐答案

好吧,您的主要问题是文本文件的格式令人恐惧.如果您的列始终是相同的(和标题),则只丢弃前七行,然后在选项卡上拆分以下行.

计算机如何分辨产品名称"是一列带有值,还是两列产品"和名称"在第二列中没有任何内容?

没有太大的帮助,但是如果可能,请尝试以更好的格式获取文件.
Well, your main problem is that the textfile is in a dreadful format. If your columns are always the same (and the header) I''d just discard the first seven lines, then split the following lines on tabs.

How can the computer tell if ''Product Name'' is one column with values, or two columns ''Product'' and ''Name'' with nothing in the second column?

Not much help, but if possible try getting the file in a better format.


您好,

要在C#中解析文本,您需要使用以下string 函数:

IndexOf()
LastIndexOf()
SubString()
Replace()
StartsWith()
EndsWith()

等等.
Hi,

To parse text in C#, you need to use following string function:

IndexOf()
LastIndexOf()
SubString()
Replace()
StartsWith()
EndsWith()

etc.


这篇关于在C#和.net中解析文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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