使用C#从许多文本文件中提取ID [英] extract ID from many Text files using C#

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

问题描述

你好

你可以帮我创建一个应用程序从文本文件中提取ID并输出到CSV,Excel,Access或任何格式都可以处理第一列的两列ID和文件名称的第二个包含ID。



ID的例子是

013-2255

013-5415

013-5154



全部以013开头 - 四个数字

Hello
can you please help me to create a App To extract ID''s from Text Files and make output to CSV, Excel,Access or any format can handle two columns the 1st for the ID and the Second to the name of the File Contained the ID.

Example of ID''s is
013-2255
013-5415
013-5154

all start with "013" the "-" the four Numbers

推荐答案

在一个回复中无法完全回答您正在寻找的答案。我们可以为您提供的提示。



以下是一些提示:



首先,要在文本文件中找到ID:

您可以使用以下技术的一些组合:

1. string.IndexOf(string)

2. string.SubString()

3. string.Contains()

4.如建议CodeNinja:[如何:使用正则表达式搜索字符串 ]

这可能需要你几天(一整天)来研究它。



接下来,关于出口数据到Excel。

有多种方法可以将数据导出到Excel文件。我记得是:

1.使用Excel.Interop

2.使用OleDB

3.使用第三方DLL

- NPOI - 导出到Excel 2003(xls)

- CloseXML - 导出到Excel 2007/2010(xlsx)

- OpenXML(Microsoft) - 导出到Excel 2007/2010(xlsx)

了解更多选项: http://stackoverflow.com/questions/444522/import-and-export-excel-what-is-the-best-library [ ^ ]

4.为了快速简便地参考,您可以搜索该项目的源代码:http://simpb.codeplex.com

- SimPB具有将数据导出到CVS和Excel的功能,你可以复制&粘贴代码供您自己使用。

5.您可以导出数据并将其作为HTML表格文件,但将文件扩展名保存为 .xls 。 Microsoft Excel会自动将其转换为Excel。



接下来,关于导出到CVS。

对于快速解决方案,您只需复制并粘贴http://simpb.codeplex.com上的代码即可。代码写在项目中。您可以尝试找到它。

您可以使用许多第三方工具。您可以在codeproject中找到它。



接下来,关于导出到Access。

我以前从未这样做过,但我知道你可以用OleDB做到这一点。



上面提到的每个组件都需要几天时间(8小时)一天)在你的项目中学习和实施它。你应该能够在一周内完成你想要的东西。



链接在哪里?谷歌很容易说出来。如果你找不到它,请在评论中发帖。
The answers that you are looking for cannot be fully answered in one reply. What we can provide you are hints.

Here are some of the hints:

First, for locating the IDs in a text file:
You can use some of the combination of the techniques below:
1. string.IndexOf(string)
2. string.SubString()
3. string.Contains()
4. as suggested by CodeNinja: [How to: Search Strings Using Regular Expressions]
This might takes you couple of days (whole day) to study it.

Next, about exporting data to Excel.
There are various of ways to export data to an Excel File. What I can recall is:
1. Using Excel.Interop
2. Using OleDB
3. Using 3rd party DLL
- NPOI - Export to Excel 2003 (xls)
- CloseXML - Export to Excel 2007/2010 (xlsx)
- OpenXML (Microsoft) - Export to Excel 2007/2010 (xlsx)
for more options: http://stackoverflow.com/questions/444522/import-and-export-excel-what-is-the-best-library[^]
4. For a quick and easy reference, you may search through the source code of this project: http://simpb.codeplex.com
- SimPB has a function of exporting data into CVS and Excel, you can copy & the paste the code for your own use.
5. You can export the data and make it as a HTML table file, but save the file extension as .xls. Microsoft Excel will automatically convert it into Excel.

Next, about exporting to CVS.
For fast solution, you may just copy and paste the code from http://simpb.codeplex.com. The codes are written inside the project. You may try to find it.
There are lots of 3rd party tools that you can use. You can find it in codeproject.

Next, about exporting to Access.
I never done this before, but I know that you can do it with OleDB.

Each of the component mentioned above will take you couple of days(8 hours a day) to study and implement it in your project. You should be able to accomplish what you want in a week of time.

Where is the link? Google can easily tell. If you can''t locate it, post it in comment.


1。从文本文件中读取每一行。

2.使用String.replace命令将 - 替换为,

,例如 eachLine = eachLine.Replace( - ,,);

3.将这些行添加到扩展名为CSV的新文本文件中

4.创建CSV文件后,只需双击该文件,它将在Excel中打开,数据在2列中

5.如果您想要列标题,只需将以下行添加到CSV文件作为第一行

ID,名称
1. Read each line from the text file.
2. Replace "-" with "," using String.replace command
e.g. eachLine = eachLine.Replace("-", ",");
3. Add these lines to a new text file with extension CSV
4. After creating CSV file, just double click the file, it will open in Excel with data in 2 columns
5. If you want the column headers, just add the following line to the CSV file as first line
ID,Name


Regex

--Sj
Regex
--Sj


这篇关于使用C#从许多文本文件中提取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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