Newsgroups: comp.lang.javascript
From: Fox <maho...@eatel.net>
Date: Tue, 28 Nov 2000 04:38:54 GMT
Local: Mon, Nov 27 2000 11:38 pm
Subject: Re: CSV to array
Client-side JavaScript won't open a csv file (or anything other than a
.js file), so the I developed a little tool that might assist you in converting csv into a two-dimensional JavaScript Array. Instructions: Open the csv file in a text processor. Select All and copy. Run the following converter "app" in a browser and paste the csv data After a second or so, the original file will be converted into Features: All array members generated are strings. Keep this in mind when dealing The fields of Record #0 are the names of the fields. The number of records can be gotten by (csvData.length - 1) [remember This program makes no assumptions about empty fields. The number of I wrote this on a Mac. I THINK I took care of the PC newline issue. If Hope this helps (code follows), Fox <xmp><!-- remove this line to run --> <title>CSV to JS Converter</title> function var data = f.data.value; forequote = data.indexOf('"', backquote + 1); while(forequote != -1) tdata = data.substring(forequote, backquote); data = data.substring(0, forequote) + tsplit + data.substring(backquote); var tempArray = data.split("\r"); if(tempArray.length == 1) tempArray = data.split("\n"); var fields; for (var r = 0; r < tempArray.length; r++) f.data.value = output; } </script> <body> </xmp><!-- remove this line to run --> ************************************************************* Jeff Thies wrote:
> I'm looking for a reasonable way to turn CSV data into an array. The > Seems like there's a lot of potential gotchas! > Jeff You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||