平面文件分析器程序 [英] Flat file parser routine

查看:115
本文介绍了平面文件分析器程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个平坦的文件。该前五个字符在每一行确定行属于哪个类型。
每种类型都有几个字段和所有固定长度。 ?选项我如何去解析该文件并将其存储在数据库中。

We have a flat file.The First five characters on each line determines which type the line belongs to. Each type has few fields and all are fixed length. How do i go about parsing the file and store it in a database?

情侣:

1 )为每个类型的XML模板和基于第一五个字符确定使用解析线

1) Create a XML template for each type and based on the first five characters determine which template to use to parse the line

<FileMap>
    <Field Name="FirstName" Start="0" Length="5"/>
    <Field Name="LastName" Start="5" Length="10"/>
    <Field Name="Address" Start="15" Length="15"/>
    <Field Name="City" Start="30" Length="14"/>
    <Field Name="State" Start="44" Length="2"/>
    <Field Name="Zip" Start="46" Length="5"/>
</FileMap>



2)使用fileHelpers库(的 http://www.filehelpers.net/

任何其他建议?请让我知道

Any other suggestions? Please let me know

推荐答案

Microsoft.VisualBasic.FileIO.TextFieldParser 类做分析结构化文本文件的一个很好的工作。您可以从C#中使用它。只需添加到Microsoft.VisualBasic.dll中的引用,一个在代码中使用Microsoft.VisualBasic.FileIO 语句。

The Microsoft.VisualBasic.FileIO.TextFieldParser class does a very good job of parsing structured text files. You can use it from C#. Just add a reference to Microsoft.VisualBasic.dll, and a using Microsoft.VisualBasic.FileIO statement in your code.

这篇关于平面文件分析器程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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