Results 1 to 3 of 3

Thread: Parsing through CSV to get specific name/value pairs

  1. #1
    Join Date
    Dec 2003

    Parsing through CSV to get specific name/value pairs


    I have a task that could be made much easier if I built a simple tool to parse through a CSV data pasted in a text area and it spits out specific the parts the name/value pairs I need. I do not have the luxury of a database and the data is a bit sensitive or else I would not be needing your fantastic assistance and I would have churned out some server-side magic.

    Anyway, what is tripping me up is the necessity for regular expressions (and my lack of experience in this area in general), which can drive a man to drink. I can work with the code to get the specific parts I need and manipulate what is spit out to my specifications but its the starting point that I need help with.

    I pasted a sample section of the data I need to parse through. I am pretty sure I can work with the data once it gets split into an array that can be searched through.

    I appreciate any assistance on this matter.


  2. #2
    Join Date
    Dec 2005
    You're text file does not look like a true CSV file.

    It appears you define col1-col6, but you have 7 cols of text without a end "\n"
    or a "Head#" that does not define enough columns of data.

    What kind of information are you trying to parse out of the text file?
    Are the rows ending with a '\n' or a ',' character?
    Can you provide a bit more information about the data you have?

  3. #3
    Join Date
    Apr 2010
    As you observe, the operative word here is 'split' . Try this:

    function makeCsvArray(text) {
      var rows, i;
      var cols = Array();
      rows = text.split('\n');
      for (i=0; i<rows.length; i++) {
        cols[i] = rows[i].split(',');
      return cols;
    var csvArray = makeCsvArray(textField);
    Have fun.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center