如何解析CSV文件 [英] How to parse CSV file
问题描述
您好,
我需要解析返回域DNS记录的字符串,并将此
数据放入DataTable。我没有太多解析字符串的经验,所以
我不知道如何做到这一点的有效方法。我找到了一些例子
的CSV解析器类,但不知道如何在我的情况下使用它们。
这是一个字符串的例子:
RRs \ nsname:@; priority:5; address:mail.domainname.net .; rectype:
MX; \ nsubname:dns ; priority:1; address:ns1.domainhost.net .; rectype:
NS; \ nsubname:dns; priority:2; address:ns2.domainhost.net .; rectype:
NS; \ nsnname:help; priority:0; address:67.22.36.4; rectype:A; \ nsnamename:
mail; priority:0; address:domainname.net 。; rectype:CNAME; \ nsname:
support;优先级:0;地址:help.domainhost.net .; rectype:CNAME; \ nsubname:
text ; priority:0; address:\" tex value \" ;; rectype:TXT;
每条记录用\ n分隔。列是:
子名
rectype
优先
地址
如果你能指出正确的方向,我将非常感激
如何有效地解析这个字符串。
谢谢你,
彼得
Hello,
I need to parse a string that returns the domain DNS records and to put this
data into a DataTable. I don''t have much experience in parsing strings, so
I''m not aware of the efficient way how to do this. I''ve found some examples
of CSV parser classes, but not sure how to use them in my case.
Here is an example of the string:
RRs\nsubname: @;priority: 5;address: mail.domainname.net.;rectype:
MX;\nsubname: dns;priority: 1;address: ns1.domainhost.net.;rectype:
NS;\nsubname: dns;priority: 2;address: ns2.domainhost.net.;rectype:
NS;\nsubname: help;priority: 0;address: 67.22.36.4;rectype: A;\nsubname:
mail;priority: 0;address: domainname.net.;rectype: CNAME;\nsubname:
support;priority: 0;address: help.domainhost.net.;rectype: CNAME;\nsubname:
text;priority: 0;address: \"tex value\";rectype: TXT;
Each record is separated by "\n". The columns are:
subname
rectype
priority
address
I would appreciate very much if you could point me to the right direction
how to parse this string efficiently.
Thank you,
Peter
推荐答案
彼得,
在互联网上使用OleDB这个大约1000.000个样本如何做到这一点。
Cor
" Peter Afonin" < pe **** @gudzon.netschreef在bericht
新闻:%2 **************** @ TK2MSFTNGP06.phx.gbl ...
Peter,
Use OleDB for this about 1000.000 samples on Internet how to do this.
Cor
"Peter Afonin" <pe****@gudzon.netschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
你好,
我需要解析一个返回域名DNS记录的字符串并放入
将此数据转换为DataTable。我在解析
字符串方面没有太多经验,所以我不知道如何做到这一点的有效方法。我找到了
一些CSV解析器类的例子,但不知道如何在我的
案例中使用它们。
以下是字符串的示例:
RRs \ nsubname:@; priority:5; address:mail.domainname.net .; rectype:
MX; \ nsubname:dns; priority:1; address:ns1.domainhost.net .; rectype:
NS; \ nsubname:dns; priority:2; address:ns2.domainhost。 net .; rectype:
NS; \ nsnsname:help; priority:0; address:67.22.36.4; rectype:A; \ nsnamename:
mail; priority :0;地址:domainname.net .; rectype:CNAME; \ nsname:
support;优先级:0;地址:help.domainhost.net .; rectype:
CNAME; \ nsname:text; priority:0; address:\" tex value \" ;; rectype:TXT;
每条记录用\\分隔\
" ;.列是:
子名
rectype
优先
地址
如果你能指出正确的方向,我将非常感激
如何有效地解析这个字符串。
谢谢你,
Peter
Hello,
I need to parse a string that returns the domain DNS records and to put
this data into a DataTable. I don''t have much experience in parsing
strings, so I''m not aware of the efficient way how to do this. I''ve found
some examples of CSV parser classes, but not sure how to use them in my
case.
Here is an example of the string:
RRs\nsubname: @;priority: 5;address: mail.domainname.net.;rectype:
MX;\nsubname: dns;priority: 1;address: ns1.domainhost.net.;rectype:
NS;\nsubname: dns;priority: 2;address: ns2.domainhost.net.;rectype:
NS;\nsubname: help;priority: 0;address: 67.22.36.4;rectype: A;\nsubname:
mail;priority: 0;address: domainname.net.;rectype: CNAME;\nsubname:
support;priority: 0;address: help.domainhost.net.;rectype:
CNAME;\nsubname: text;priority: 0;address: \"tex value\";rectype: TXT;
Each record is separated by "\n". The columns are:
subname
rectype
priority
address
I would appreciate very much if you could point me to the right direction
how to parse this string efficiently.
Thank you,
Peter
谢谢你,Cor。我会试着找到它们,到目前为止没有运气,也许使用
错误的搜索条件。
彼得
" Cor Ligthert [MVP]" < no ************ @ planet.nlwrote in message
news:66 ****************** **************** @ microsof t.com ...
Thank you, Cor. I''ll try to find them, had no luck so far, perhaps using
wrong search terms.
Peter
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:66**********************************@microsof t.com...
Peter,
在互联网上使用OleDB这个大约1000.000个样本如何做到这一点。
Cor
" Peter Afonin" < pe **** @gudzon.netschreef在bericht
新闻:%2 **************** @ TK2MSFTNGP06.phx.gbl ...
Peter,
Use OleDB for this about 1000.000 samples on Internet how to do this.
Cor
"Peter Afonin" <pe****@gudzon.netschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
>您好,
我需要解析返回域DNS记录的字符串并将此数据放入一个DataTable。我在解析字符串方面没有多少经验,所以我不知道如何做到这一点的有效方法。我找到了一些CSV解析器类的例子,但不知道如何在我的
情况下使用它们。
这是一个字符串示例:
RRs \ nsubname:@; priority:5; address:mail.domainname.net .; rectype:
MX; \ nsubname:dns; priority:1; address:ns1.domainhost.net 。; rectype:
NS; \ nsubname:dns; priority:2; address:ns2.domainhost.net .; rectype:
NS; \ nsubname:help; priority:0; address:67.22 .36.4; rectype:A; \ nsname:
mail;优先级:0;地址:domainname.net .; rectype:CNAME; \ nsubname:
支持;优先级:0;地址:help。 domainhost.net .; rectype:
CNAME; \ nsnamename:text; priority:0; address:\" tex value \" ;; rectype:TXT;
每条记录由\ n分隔。专栏是:
子名
直接
优先级
如果你能指出我正确的方向,我将非常感激
如何有效地解析这个字符串。
谢谢,
Peter
>Hello,
I need to parse a string that returns the domain DNS records and to put
this data into a DataTable. I don''t have much experience in parsing
strings, so I''m not aware of the efficient way how to do this. I''ve found
some examples of CSV parser classes, but not sure how to use them in my
case.
Here is an example of the string:
RRs\nsubname: @;priority: 5;address: mail.domainname.net.;rectype:
MX;\nsubname: dns;priority: 1;address: ns1.domainhost.net.;rectype:
NS;\nsubname: dns;priority: 2;address: ns2.domainhost.net.;rectype:
NS;\nsubname: help;priority: 0;address: 67.22.36.4;rectype: A;\nsubname:
mail;priority: 0;address: domainname.net.;rectype: CNAME;\nsubname:
support;priority: 0;address: help.domainhost.net.;rectype:
CNAME;\nsubname: text;priority: 0;address: \"tex value\";rectype: TXT;
Each record is separated by "\n". The columns are:
subname
rectype
priority
address
I would appreciate very much if you could point me to the right direction
how to parse this string efficiently.
Thank you,
Peter
>
虽然OLEDB是一个选项,你也可以在纯粹的
托管代码中更有效地完成它:
http://www.codeproject.com/KB/database/CsvReader.aspx
我以前用过这个 - 它很棒。
(搜索条件是:csv阅读器C#)
Marc
While OLEDB is an option, you can also do it (more efficiently) in pure
managed code:
http://www.codeproject.com/KB/database/CsvReader.aspx
I''ve used this one before - it works great.
(search terms were: csv reader C#)
Marc
这篇关于如何解析CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!