473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

reading and splitting a 'csv' file

tor
Hello
I have a csv file i need to split into elements.

line example:
element1;element2;elemtent3 --> e[0] = element1 e[1] = element2 e[2] =
element3
element1;"elem;ent2";elemtent3 --> e[0] = element1 e[1] = elem;ent2 e[2]
= element3
element1;elem\;ent2;elemtent3 --> e[0] = element1 e[1] = elem;ent2 e[2]
= element3

My question is how can i do a correct split.
line.split(';') works only on the first line

Torfinn

Nov 15 '05 #1
2 2340
Hi,

See this link
http://msdn.microsoft.com/library/de...xtFromFile.asp
there you will see how to read a file,
you simply add these lines inside the loop

string[] elements = line.Split( new char[] { ','} );
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"tor" <to******@hotmail.com> wrote in message
news:Ow****************@TK2MSFTNGP09.phx.gbl...
Hello
I have a csv file i need to split into elements.

line example:
element1;element2;elemtent3 --> e[0] = element1 e[1] = element2 e[2] =
element3
element1;"elem;ent2";elemtent3 --> e[0] = element1 e[1] = elem;ent2 e[2] = element3
element1;elem\;ent2;elemtent3 --> e[0] = element1 e[1] = elem;ent2 e[2] = element3

My question is how can i do a correct split.
line.split(';') works only on the first line

Torfinn

Nov 15 '05 #2
Hi,
converting the csv.. to DataSet is very simple..
here is the exampl code
================================================== =======
OleDbConnection csvConn = new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;"+
"Data Source=" + "<specify
the path."+ ";" +
"Extended
Properties=\"text;HDR=YES;FMT=Delimited\"");

OleDbDataAdapter csvDa = new OleDbDataAdapter("SELECT *
FROM " + "specify the csv file
name.<<fileName>>" ,csvConn);

Take the csvDA and Make as many DataSets u like...
Note that the first row is taken as the column header in
Data Set

mail me if you have trouble in doing the above solution

Regs
PRadeep
pr*******@hotmail.com
-----Original Message-----
Hi,

See this link
http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/cpguide/html/cpconReadingTextFromFile.asp

there you will see how to read a file,
you simply add these lines inside the loop

string[] elements = line.Split( new char[] { ','} );
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"tor" <to******@hotmail.com> wrote in message
news:Ow****************@TK2MSFTNGP09.phx.gbl...
Hello
I have a csv file i need to split into elements.

line example:
element1;element2;elemtent3 --> e[0] = element1 e [1] = element2 e[2] = element3
element1;"elem;ent2";elemtent3 --> e[0] = element1 e
[1] = elem;ent2e[2]
= element3
element1;elem\;ent2;elemtent3 --> e[0] = element1 e
[1] = elem;ent2e[2]
= element3

My question is how can i do a correct split.
line.split(';') works only on the first line

Torfinn

.

Nov 15 '05 #3

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

Similar topics

18
by: robsom | last post by:
Hi, I have a problem with a small python program I'm trying to write and I hope somebody may help me. I'm working on tables of this kind: CGA 1988 06 21 13 48 G500-050 D 509.62 J.. R1 1993 01...
7
by: RFQ | last post by:
Hi, I'm struggling here to do the following with any success: I have a comma delimited file where each line in the file is something like: PNumber,3056,Contractor,XYZ Contracting,Architect,ABC...
2
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
2
by: Antonio Tirado | last post by:
(ASP.NET c# Question) Hi, I have this odd problem: I receive a CSV File through file upload. Using an OleDB.Datareader i read each row of the file and insert it into SQL. The problem is...
12
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my...
0
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads...
4
by: archana | last post by:
Hi all, I want to read csv file into datatable. Is there any csv reader and writer available for freeware. I am reading csv file using schema.ini file. I don't want this dependency. The...
1
by: anii | last post by:
Hi! I'm working on a piece of code for school. =) in C++. (I've read the rules and understand that i can't put all of the code here and ask for all of the code) I've got all (or most) of the code...
2
by: cluce | last post by:
I am trying to read a csv file with user info (username, password, email, address, city, zip, state, etc.) I am inserting the username, password, email into the aspnet_memberhsip table using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.