473,654 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem Parsing CSV File

2 New Member
Hi,

m using split function to parse the csv file ..... i m getting problem in one line of file which looks like this :

"BLUEUSBXM" ,"X-MICRO (XBT-DG5R (C) R1) BLUETOOTH USB DONGLE PLUS, CLASS 1",360,0.00,"", "",0.00,"",0,0. 00,"","T1","",5 .58,"4000",8.50 ,0.00,"02/10/2006",0.00,"16/04/2007"


now the problem is it parses first field properly.
BUT
Not parsing second field.....
avars = split(line,",")
should give:
avars(1) = "X-MICRO (XBT-DG5R (C) R1) BLUETOOTH USB DONGLE PLUS, CLASS 1"

instead of that it gives me:
avars(1) = "X-MICRO (XBT-DG5R (C) R1) BLUETOOTH USB DONGLE PLUS"

how can i solve this problem....

Thanks
Pindoriya1
Jul 3 '08 #1
12 4615
DrBunchman
979 Recognized Expert Contributor
The Split function is working correctly - it is splitting the file every time it finds a comma and there is a comma after the word PLUS.

To solve this you could make sure that all the fields that are entered into the CSV file have any comma's removed or you could parse the file in a different way.

Dr B
Jul 3 '08 #2
pindoriya1
2 New Member
The Split function is working correctly - it is splitting the file every time it finds a comma and there is a comma after the word PLUS.

To solve this you could make sure that all the fields that are entered into the CSV file have any comma's removed or you could parse the file in a different way.

Dr B


Thanks I know that that is why i want solution for that.....
actually the file comes from account software SO EITHER we change in the software OR we solve this problem once and for alll the time we get such feeds form anywhere.....

i prefer second way, as rather than telling accountign people to change name.... i want solution which i can use everywhere i get this situation...... ..........

YOU SUGGEST I COULD PARSE FILE IN DIFFERENT WAY....
so can you suggest me one or two of such ways....

thank you
pindoriya1
Jul 3 '08 #3
DrBunchman
979 Recognized Expert Contributor
The only thing I can think of that you might be able to do here is to loop through the string checking each character to see whether it's a comma. If it is a comma then check the next character to see whether it is a space - if so then it's going to be a comma inside one of your fields rather than one of your delimiters so you can ignore it.

It's not foolproof as somebody might enter some text which had a comma without a space after it but it will yield better results than the existing method.

Dr B
Jul 3 '08 #4
jhardman
3,406 Recognized Expert Specialist
best method: in the app that saves the CSV file, replace all commas with ",". You will also need to replace all instances in the existing csv file where there is a comma that isn't used as a delimiter with "," This will display correctly, can even be copied and pasted correctly, and the people who use it will never know the difference.

Second method: Try DrB's solution, but I would be happier if you added a trim() call to the original function that saves data to make sure no fields begin with a space, but this is still far from fool-proof. And if you are going to alter the app that saves the data, you might as well use the first solution.

Third method: Get a list of all products that have a comma, before you parse the .csv file, replace those texts with a version that doesn't contain commas. I would only recommend this if you have absolutely no access to the app that saves the csv file and you have a definite list of texts that have commas.

Let me know if this helps.

Jared
Jul 8 '08 #5
danp129
323 Recognized Expert Contributor
use regular expressions to parse CSV strings
Jul 9 '08 #6
jhardman
3,406 Recognized Expert Specialist
best method: in the app that saves the CSV file, replace all commas with ",". You will also need to replace all instances in the existing csv file where there is a comma that isn't used as a delimiter with "," This will display correctly, can even be copied and pasted correctly, and the people who use it will never know the difference.
and I spent all that time typing in the character code for a comma... I didn't notice that Bytes.com just replaced my code with commas. the code should be an ampersand followed by "#44;".

Jared
Jul 9 '08 #7
jhardman
3,406 Recognized Expert Specialist
use regular expressions to parse CSV strings
yes, I agree. Regex would be a good way to do the replaces.

Jared
Jul 9 '08 #8
DrBunchman
979 Recognized Expert Contributor
Of course, didn't think of that.

Good idea.
Jul 10 '08 #9
danp129
323 Recognized Expert Contributor
As an alternative to regexp's (due to the complexity of writing them) you could also use an ODBC connection with the Microsoft Text Driver to read the CSV file and select a specific record or recurse through all of them.

Provider=MSDASQ L; Driver={Microso ft Text Driver (*.txt; *.csv)}; DBQ=C:\path\;

In this case, the c:\path\ folder would be equivilant to a "database" and the filename would be the table. So if you have "c:\path\mydata .csv" then your select statement would be something like "Select * from mydata.csv".

There may be some limitations using this method, such as limited to 255 character length per field or maybe there is not a limit but the driver may only look at the first 10 rows to decide what the max length of a field is w/o editing the registry or creating an .ini file for the driver. You may also not be able to join "tables" (files) like a normal database, I haven't used csv files for quite some time so I can't say.

You can find some examples searching for: "Microsoft Text Driver" asp
Jul 10 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1489
by: burn_hall | last post by:
Hi, I have a problem and can't figure it out and need your help, please look at the following code and the output also a xml file snippet is down there too. Looking at the output I don't know why it's not according to the code. Following code is pretty much clear: When method starts execution <Pat> Node is passed it has childNodes Inside for-loop
2
3946
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home Canonicalpath-Directory4: \\wkdis3\ROOT\home\bwe\ You selected the file named AAA.XML getXmlAlgorithmDocument(): IOException Not logged in
11
3562
by: Johnny Lee | last post by:
Hi, I was using urllib to grab urls from web. here is the work flow of my program: 1. Get base url and max number of urls from user 2. Call filter to validate the base url 3. Read the source of the base url and grab all the urls from "href" property of "a" tag 4. Call filter to validate every url grabbed 5. Continue 3-4 until the number of url grabbed gets the limit
10
2537
by: Bryce Calhoun | last post by:
Hello, First of all, this is a .NET 1.1 component I'm creating. SUMMARY ----------------------- This component that I'm creating is, for all intents and purposes, a document parser (I'm actually deserializing a SOAP document into an object and parsing out the fields, but that's fairly immaterial to this
4
4857
by: Rick Walsh | last post by:
I have an HTML table in the following format: <table> <tr><td>Header 1</td><td>Header 2</td></tr> <tr><td>1</td><td>2</td></tr> <tr><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td></tr> </table> With an XSLT styles sheet, I can use for-each to grab the values in
1
3698
by: Martin Pöpping | last post by:
Hello, I´ve a problem with parsing a double value from an xml file. My code looks like this: int concept_id; double rank; XmlElement root = documentXMLString.DocumentElement; XmlNodeList records = root.ChildNodes;
27
5120
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
12
3396
by: Julian | last post by:
Hi, I am having problems with a function that I have been using in my program to read sentences from a 'command file' and parse them into commands. the surprising thing is that the program works fine on some computers and not so fine on others. I tried debugging and cannot make any sense of it. I narrowed it down to the seekg function and made this simple program which (from what I understand) does not seem to be working as expected in all...
7
2844
by: souravmallik | last post by:
Hello, I'm facing a big logical problem while writing a parser in VC++ using C. I have to parse a file in a chunk of bytes in a round robin fashion. Means, when I select a file, the parser will read first 512kb(IBUFFSIZE) of data, then move to next file and parse the same way. This way I can parse a number of file spreaded over different directory uniformly. I'm keeping a meta data in a file where I'm keeping the track of file parse...
0
8380
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8296
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
8710
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...
1
8497
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7310
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...
0
5627
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();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2721
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
1598
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.