473,804 Members | 3,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parseing data in CSV files

How would you parse this type of file into an array?

"Test","Hel p, data","hello there, this text has commas","commas seperate
data, and in quotes they dont"

where the double quotes are the string markers, which can contain comma's,
but when you are not in a quote block the commas seperate the data... you're
basic Comma seperated value file... thanks

(i know split doesnt work for this... thats why im asking)
Nov 21 '05 #1
6 1232
Brian,

Why does the split on "," (all three characters I write) not work,

When you than eliminiate the first position from the first arrayItem and the
last postition from the last Array item with substring, you have what you
want in my idea?

Cor
Nov 21 '05 #2
the reason it wont work is because not every field is in quotes... so data
can look like this

"hello",,,,,,,, "field again","another , field here","bad huh?",,,

and at each comma that isnt in quotes is a new field... kind of makes
splitting alone really hard... i was going to split on the string quote
comma quote "","" like that, but because some fields have no quotes its a
lot harder then a simple split and removeing the starting and ending quotes

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:uR******** *****@TK2MSFTNG P12.phx.gbl...
Brian,

Why does the split on "," (all three characters I write) not work,

When you than eliminiate the first position from the first arrayItem and
the
last postition from the last Array item with substring, you have what you
want in my idea?

Cor

Nov 21 '05 #3
"Brian Henry" <br**********@n ewsgroups.nospa m> wrote in message
news:Ol******** ******@TK2MSFTN GP09.phx.gbl...
How would you parse this type of file into an array?

"Test","Hel p, data","hello there, this text has commas","commas seperate
data, and in quotes they dont"

where the double quotes are the string markers, which can contain comma's,
but when you are not in a quote block the commas seperate the data... you're basic Comma seperated value file... thanks

(i know split doesnt work for this... thats why im asking)

I think I solved this some time ago but I cant remember how & dont now what
I did with the source code. I seem to remember changing single to double
quotes but the reason why escapes me now.
It occurs to me now however that splitting on commas then looping through
the bits extracted joining together any which start with a " or even a '
perhaps until you have a trailing " or ' to match. Then you just have the
problem of testing for 'escaped' or doubled quotes such as 123,"text
"",here""", 246

--
Jonathan Bailey.
Nov 21 '05 #4
Brian,

It seems as an original CSV so you can try that with OleDb

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\Test1\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
Dim conn As New OleDb.OleDbConn ection(ConStr)
Dim da As New OleDb.OleDbData Adapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try
DataGrid1.DataS ource = ds.Tables(0)
End Sub

I hope this helps a little bit?

Cor
Nov 21 '05 #5
that might be what I need, thanks, I'll try it out

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:u3******** ******@tk2msftn gp13.phx.gbl...
Brian,

It seems as an original CSV so you can try that with OleDb

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\Test1\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
Dim conn As New OleDb.OleDbConn ection(ConStr)
Dim da As New OleDb.OleDbData Adapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try
DataGrid1.DataS ource = ds.Tables(0)
End Sub

I hope this helps a little bit?

Cor

Nov 21 '05 #6
it worked, thanks!

"Brian Henry" <br**********@n ewsgroups.nospa m> wrote in message
news:es******** ******@TK2MSFTN GP09.phx.gbl...
that might be what I need, thanks, I'll try it out

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:u3******** ******@tk2msftn gp13.phx.gbl...
Brian,

It seems as an original CSV so you can try that with OleDb

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\Test1\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
Dim conn As New OleDb.OleDbConn ection(ConStr)
Dim da As New OleDb.OleDbData Adapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try
DataGrid1.DataS ource = ds.Tables(0)
End Sub

I hope this helps a little bit?

Cor


Nov 21 '05 #7

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

Similar topics

0
1914
by: tag | last post by:
Hi, I have a problem in that I need to be able to parse excel formula's and evaluate them to get results. Python is very well suited for this as it has WONDERFUL data handling capabilities. My question is : Is there an excel formula parser out there? and if not - does anyone have an idea on where to start ?
2
5544
by: Ivan | last post by:
Hi, SQL Server 2000 SP3 Windos 2000 Server SP4 I have a DTS package that imports data from a dBase IV databse with files located in two folders (dBF1 and dBF2). I use a transform data task to transform the data. They were running properly, but last week we installed W2K SP4, and
2
1817
by: Fred | last post by:
Hi, I am parsing a small xml document and the parseing goes 'all funny' when parsing this element: <useragent>Mozilla/4.61 (WinNT; I)</useragent> I've created a subclass of org.xml.sax.helpers.DefaultHandler, and an instance of this subclass is set on my org.apache.xerces.parsers.SAXParser:
2
1360
by: An S. | last post by:
I have created a little "update" system, that tells when a update from nvidia is released, currently it tells it from a "simple" protocol "S2P", i have been told that XML, is much easier, for the client to download, and then read it afterwards, sooo does anyone know a good XML parseing libary? thanks FreeGeG
4
1444
by: Keith Henderson | last post by:
I have an xml document loaded into a string that I need to parse. below is the first few elements in the xml string. <?xml version="1.0" standalone="yes"?> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded">
3
5774
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard drive onto a USB External Hard Drive. I have to assume I also copied the data. I
4
1046
by: guy | last post by:
I have a large number of html file (10,000+) and need to programmatical modify them on a regular basis. How can I determine the textual data that is present, ignoring tags etc so if i have a line such as:- <TD WIDTH="524"><B><FONT SIZE="2" FACE="Times New Roman" COLOR="#000000">Direction2</FONT></B></TD> I need to return "Direction2" and nothing else
1
1127
by: jdrechsler | last post by:
I play a game that has raw news feeds stored in txt on there website. located http://a.swirve.com/data My problem is I know nothing about PHP. The basics of what I am trying to do is scan the file, insert into a mysql database. Right now there is a whole sets worth of data. But when the next set starts there wont be that many files, or same file names used. The one thing that stays the same is the next to last file is the current hour of...
221
367767
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
0
9572
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10070
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4282
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 we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.