PDA

View Full Version : Need to parse data from CSV Files



Martin_SBT
10-25-2003, 09:43 AM
Hi

I need to be able to parse some specific data from CSV Files so i can use that data into my AMS4 project? I searched the internet for a DLL that would do that and that i could use in my project but didnt find one! Anyone can help me with that?

I am sure there is someone here that could help me with that!

thanks in advance

Martin

TJ_Tigger
10-25-2003, 04:14 PM
Do you have a sample of the data from a csv file you want to parse. If it is always in the same order, you could use the String.GetDelimited function and use the "," as a delimiter.

JimS
10-25-2003, 04:14 PM
AMS has that ability built in. In the available actions list in the String Actions, use Get Delimited String. Use a comma for the delimiter.

JimS
10-25-2003, 04:18 PM
Hey Tigg, it looks like you are a faster typer than I am, so yea, I second what you said.

Martin_SBT
10-25-2003, 04:36 PM
Thanks guys for repying! Here is a sample of the file:

"AHA05","","AHA05","","Analog"
""
"AHA12","","AHA12","","Analog"
""
"AHP05","","AHP05","","Analog"
""
"AHP12","","AHP12","","Analog"
""
"AKP12","","AKP12","","Analog"
""
"ALMCOA","","ALMCOA","","Digital"
""
"ALMCOB","","ALMCOB","","Digital"
""
"APA05","","APA05","","Analog"
""
"APP12","","APP12","","Analog"
""
"APP25A","","APP25A","","Analog"
""
I will try to use the get delimited string action as you suggested!

Thanks again!

Martin

Corey
10-25-2003, 06:45 PM
Martin, don't forget the quotation marks will be part of each item if you use a comma as the deilmiter. If you don't want that to be the case simply add a STRING > REPLACE action to strip the quotations marks afer you get the item data...

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

Martin_SBT
10-26-2003, 08:05 PM
Guys,

The string delimited action works fine, but a problem came up and i cant pinpoint what is causing it. Once i retrieved all the needed objects from the csv file, i then send the list of items to a listbox object, and for some reason, there are 2 squares that appears in front of each point names!! I attached a screenshot for you to look at. If anybody can explain to me how to get rid of that. that would be greatly appreciated.

Thanks

Martin

JimS
10-27-2003, 11:50 PM
I’ve seen this sort of thing happen when a text file gets downloaded in binary format instead of ASCII format. It has to do with the different ways that UNIX and Windows format line breaks and carriage returns. Try opening the CVS file in Notepad, do you see the same thing? You may have to massage your CVS file a bit. You might want to search the forum for #ASC_LF# to get more info.

Worm helped me out when I was having some similar problems, and he sent me some instructions. I’ll try to reword them a bit here to make them more appropriate for your situation.

First you need to define a couple of constants.

Intructions to define a constant for Carriage Return and Line Feed.
1. Click on Project
2. Choose Settings
3. Click on the Configurations TAB
4. Click on Default Build (in the left pane)
5. Click on the Note Icon with the Red Arrow under the Constants Box
6. Define the constant like this

Name: #ASC_CR#
Value: 13
Comment: Carriage Return

The click on OK.

7. Click on the Note Icon with the Red Arrow under the Constants Box (again)
6. Define the constant like this

Name: #ASC_LF#
Value: 10
Comment: Line Feed

The click on OK.

8. Close out the Project Settings Box.

How to use them

1. Use AMS's actions to do replace all instances of a Carriage Return/Line Feed with only a Line Feed

%OrigionalCVSTextFile% =TextFile.Read ("%SrcDir% \cvs.txt")
%NewCVSFile% = String.Replace ("%OrigionalCVSTextFile% ", "#ASC_CR##ASC_LF#", "#ASC_LF#")

2. Now replace all instances of a Line Feed, with a Carriage Return/Line Feed
%NewCVSFile% = String.Replace ("%OrigionalCVSTextFile% ", "#ASC_LF#", "#ASC_CR##ASC_LF#")

3. The variable %NewCVSFile% will hold the corrected version of the CVS file.

I hope this works for you. Let me know if you need more help.
If it does work, and I’m pretty sure it will, remember all credit goes to Worm. I’m just the messenger.

Corey
10-28-2003, 12:24 AM
As you guys have probably heard new version of AMS 5.0 is out this week. It has provision for the UNIX format snafu.

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

JimS
10-28-2003, 01:04 AM
Does that mean that download web file will let us choose between binary and ASCII formats? What else can we look forward to? I knew it was coming someday but I can’t find anything about it on your site. Hats off to Lorne and the rest, for coming up with features that Worm hasn’t already created a DLL for. I can’t wait to see what’s in store. Now that you let the cat out of the bag on the time table, I’ll find it as hard to go to sleep as a 6 year old on Xmas eve. Any chance we can get a sneak peek at the feature set? I guess I better start saving my pennies for the upgrade.

Corey
10-28-2003, 01:56 AM
I can't say anything more for now. But it'll all be on the site this week so you won't have to wait very long... :) But as to your first question, yes it will allow you to do that. :)

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)