如何解析text / html文档 [英] How to parse a text/html document

查看:270
本文介绍了如何解析text / html文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用HTMLAGILITY pack& amp解析html标签获得了网站的内容。将其存储在.html文件中。现在我想将这些内容存储在访问数据库中?我如何使用c#实现它?



这是我的.html文件内容的样子

I have got the contents of a website by parsing the html tags using HTMLAGILITY pack & store it in a .html file. Now i want to store those contents in access database? how do i achieve it using c#?

this is how my .html file contents look like

Date       Time             Lat       Lon  Depth   Mag Magt  Nst Gap 

2002/01/10 00:44:51.53  40.4415 -126.0167  25.37  3.92   Md   56 269  





标题应为列名&下面的内容应该是数据值



the heading should be column names & the contents below should be the data value

推荐答案

本教程演示如何使用C#应用程序中的Microsoft Access数据库 [ ^ ]



[update]解析输入文字:



一个简单的粘贴解决方案是:



拆分文字到元素,你将获得一个字符串数组

{日期,时间,拉特,......,2002/01/10,00:44:51.53 ,40.4415....}



然后查看值并使用它们。

如果您确定这些将在传入文本中出现的顺序,那将是很好的。

这可以很容易地实现:
This tutorial demonstrates using a Microsoft Access database from a C# application[^]

[update] Parsing the input text:

One simple solution for your pasting is:

Split the text to elements, you will get an array of string
{ "Date", "Time", "Lat", .... , "2002/01/10", "00:44:51.53", "40.4415" .... }

then go through the values and use them.
that will be good if you are sure about the order in which those will appear in the incoming text.
This can be achieved easily like this:
string[] values = Regex.Split(YourText, @"\D+");
foreach (string val in values)
{
   // do stuff with the elements ...
}

// OR this:
double LAT = Convert.ToDouble(values[11]); // take the elements according to their position.
double LON = Convert.ToDouble(values[12]);
// and so on ...

但是,我强烈建议您学习C#Regex 以适应由于文本格式化而未来发生的任何需求,以及一般来说,在我看来,Regex对于开发人员来说几乎是必不可少的工具。 />




一些正则表达式链接:

30分钟正则表达式教程 [ ^ ]

轻松学习正则表达式(RegEx) [ ^ ]



[/ update]



祝你好运,

Edo

However, I strongly suggest you learn C# Regex to accommodate for any needs that rise due to the formatting of the text, future changes and generally speaking, Regex in my opintion is pretty much a must tool for a developer.


Some Regex links:
The 30 Minute Regex Tutorial[^]
Learn Regular Expressions (RegEx) with Ease[^]

[/update]

Good luck,
Edo


这篇关于如何解析text / html文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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