473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to parse CSV file

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

Jun 27 '08 #1
11 2336
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...
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
Jun 27 '08 #2
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,

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...
>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
Jun 27 '08 #3
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
Jun 27 '08 #4
On May 18, 9:45*pm, "Peter Afonin" <pet...@gudzon.netwrote:
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
Hi,

Go to opennetcf.org and download the source code of the library they
offer, they provide a very straigforward provider
Jun 27 '08 #5
Thank you very much everyone, I'll try it.

Peter

"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:eb**********************************@f36g2000 hsa.googlegroups.com...
On May 18, 9:45 pm, "Peter Afonin" <pet...@gudzon.netwrote:
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
Hi,

Go to opennetcf.org and download the source code of the library they
offer, they provide a very straigforward provider

Jun 27 '08 #6
Peter,

I saw it, all those samples are in Visual Basic, basicly it is this, have a
look at the extened properties as you have problems.

I just have copied this somewhere from Internet I did not test it, but I see
at first sight no problems, it is quiet standard.

\\\
string path = @"C:\TEST\";
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=" + path + ";Extended
Properties=\"text;HDR=No;IMEX=1;FMT=Delimited\"");
System.Data.OleDb.OleDbCommand cmd = new
System.Data.OleDb.OleDbCommand("SELECT * FROM sample.csv", conn);
cmd.Connection = conn;
System.Data.OleDb.OleDbDataAdapter adapter = new
System.Data.OleDb.OleDbDataAdapter(cmd);
System.Data.DataSet ds = new DataSet();
conn.Open();
adapter.Fill(ds);
conn.Close();

///

Cor

"Peter Afonin" <pe****@gudzon.netschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
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,

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...
>>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
Jun 27 '08 #7
Thank you, Cor.

I've tried this and some other examples. Unfortunately, I'm not dealing
exactly with CSV file, I'm dealing with a string, although I can probably
create a CSV file out of it using Stream. I'm trying to do this, but I'm not
sure that I'm going the right way. Here is my string again:

RRs\nsubname: @;priority: 5;address: mail.russianalaska.ru.;rectype:
MX;\nsubname: dns;priority: 1;address: ns1.seattlehost.net.;rectype:
NS;\nsubname: dns;priority: 2;address: ns2.seattlehost.net.;rectype:
NS;\nsubname: help;priority: 0;address: 67.18.36.3;rectype: A;\nsubname:
mail;priority: 0;address: russianalaska.ru.;rectype: CNAME;\nsubname:
support;priority: 0;address: help.seattlehost.net.;rectype: CNAME;\nsubname:
text;priority: 0;address: \"tex value\";rectype: TXT;\nSRV\nservice:
_sip._udp;rectype: SRV;priority: 1;weight: 0;port: 5060;target:
sip.russianalaska.ru.;\n

Peter

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:3E**********************************@microsof t.com...
Peter,

I saw it, all those samples are in Visual Basic, basicly it is this, have
a look at the extened properties as you have problems.

I just have copied this somewhere from Internet I did not test it, but I
see at first sight no problems, it is quiet standard.

\\\
string path = @"C:\TEST\";
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=" + path + ";Extended
Properties=\"text;HDR=No;IMEX=1;FMT=Delimited\"");
System.Data.OleDb.OleDbCommand cmd = new
System.Data.OleDb.OleDbCommand("SELECT * FROM sample.csv", conn);
cmd.Connection = conn;
System.Data.OleDb.OleDbDataAdapter adapter = new
System.Data.OleDb.OleDbDataAdapter(cmd);
System.Data.DataSet ds = new DataSet();
conn.Open();
adapter.Fill(ds);
conn.Close();

///

Cor

"Peter Afonin" <pe****@gudzon.netschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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**********************************@microso ft.com...
>>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.. .
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
Jun 27 '08 #8
Well, as you say: that certainly isn't CSV ;-p

The first thing to do would be to understand the rules... especially
regarding things like semicolons in escaped literals - but assuming
something simple, you could do this with standard string functions:

string data = "RRs\nsubname: @;priority: 5;address:
mail.russianalaska.ru.;rectype: MX;\nsubname: dns;priority: 1;address:
ns1.seattlehost.net.;rectype: NS;\nsubname: dns;priority: 2;address:
ns2.seattlehost.net.;rectype: NS;\nsubname: help;priority: 0;address:
67.18.36.3;rectype: A;\nsubname: mail;priority: 0;address:
russianalaska.ru.;rectype: CNAME;\nsubname: support;priority:
0;address: help.seattlehost.net.;rectype: CNAME;\nsubname:
text;priority: 0;address: \"tex value\";rectype: TXT;\nSRV\nservice:
_sip._udp;rectype: SRV;priority: 1;weight: 0;port: 5060;target:
sip.russianalaska.ru.;\n";
string[] lines = data.Split('\n');
for (int i = 1; i < lines.Length; i++)
{ // (skip first line)
string[] pairs = lines[i].Split(';');
foreach (string pair in pairs)
{
int index = pair.IndexOf(':');
if (index < 0) continue;
string key = pair.Substring(0, index).Trim(),
value = pair.Substring(index + 1).Trim();

Console.WriteLine("{0}: {1}={2}", i, key, value);
}
}
Jun 27 '08 #9
Thank you, Marc, I'll try. I thought it might be easier to try to convert it
to CSV, but I guess not...

Peter

"Marc Gravell" <ma**********@gmail.comwrote in message
news:5e**********************************@24g2000h sh.googlegroups.com...
Well, as you say: that certainly isn't CSV ;-p

The first thing to do would be to understand the rules... especially
regarding things like semicolons in escaped literals - but assuming
something simple, you could do this with standard string functions:

string data = "RRs\nsubname: @;priority: 5;address:
mail.russianalaska.ru.;rectype: MX;\nsubname: dns;priority: 1;address:
ns1.seattlehost.net.;rectype: NS;\nsubname: dns;priority: 2;address:
ns2.seattlehost.net.;rectype: NS;\nsubname: help;priority: 0;address:
67.18.36.3;rectype: A;\nsubname: mail;priority: 0;address:
russianalaska.ru.;rectype: CNAME;\nsubname: support;priority:
0;address: help.seattlehost.net.;rectype: CNAME;\nsubname:
text;priority: 0;address: \"tex value\";rectype: TXT;\nSRV\nservice:
_sip._udp;rectype: SRV;priority: 1;weight: 0;port: 5060;target:
sip.russianalaska.ru.;\n";
string[] lines = data.Split('\n');
for (int i = 1; i < lines.Length; i++)
{ // (skip first line)
string[] pairs = lines[i].Split(';');
foreach (string pair in pairs)
{
int index = pair.IndexOf(':');
if (index < 0) continue;
string key = pair.Substring(0, index).Trim(),
value = pair.Substring(index + 1).Trim();

Console.WriteLine("{0}: {1}={2}", i, key, value);
}
}
Jun 27 '08 #10
Marc, thank you very much again, this worked very well for me.

Peter

"Marc Gravell" <ma**********@gmail.comwrote in message
news:5e**********************************@24g2000h sh.googlegroups.com...
Well, as you say: that certainly isn't CSV ;-p

The first thing to do would be to understand the rules... especially
regarding things like semicolons in escaped literals - but assuming
something simple, you could do this with standard string functions:

string data = "RRs\nsubname: @;priority: 5;address:
mail.russianalaska.ru.;rectype: MX;\nsubname: dns;priority: 1;address:
ns1.seattlehost.net.;rectype: NS;\nsubname: dns;priority: 2;address:
ns2.seattlehost.net.;rectype: NS;\nsubname: help;priority: 0;address:
67.18.36.3;rectype: A;\nsubname: mail;priority: 0;address:
russianalaska.ru.;rectype: CNAME;\nsubname: support;priority:
0;address: help.seattlehost.net.;rectype: CNAME;\nsubname:
text;priority: 0;address: \"tex value\";rectype: TXT;\nSRV\nservice:
_sip._udp;rectype: SRV;priority: 1;weight: 0;port: 5060;target:
sip.russianalaska.ru.;\n";
string[] lines = data.Split('\n');
for (int i = 1; i < lines.Length; i++)
{ // (skip first line)
string[] pairs = lines[i].Split(';');
foreach (string pair in pairs)
{
int index = pair.IndexOf(':');
if (index < 0) continue;
string key = pair.Substring(0, index).Trim(),
value = pair.Substring(index + 1).Trim();

Console.WriteLine("{0}: {1}={2}", i, key, value);
}
}
Jun 27 '08 #11
OrchidGrid supports parsing data from CVS file.

Could find it from www.springsys.com
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

Jun 27 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2383
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one...
22
872
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
3
2640
by: slylos | last post by:
I've got a section of code in my app that keeps track of how much time an employee has accrued, which equals out to 1.33 days of PTO per month. I'm trying to store the time accrued so far in an...
6
8537
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
5
64579
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
64003
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
11
3493
by: Peter Pei | last post by:
One bad design about elementtree is that it has different ways parsing a string and a file, even worse they return different objects: 1) When you parse a file, you can simply call parse, which...
2
3207
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString",...
6
2961
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hello, I have an XML file generated from a third party application that I would like to parse. Ideally, I plan on having a windows service setup to scan various folders for XML files and parse the...
5
2682
by: goldtech | last post by:
SAX XML Parse Python error message Hi, My first attempt at SAX, but have an error message I need help with. I cite the error message, code, and xml below. Be grateful if anyone can tell me...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.