本文介绍了如何解析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

推荐答案

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对于开发人员来说几乎是必不可少的工具。 />




一些正则表达式链接:

[]

[]



[/ 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文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:15