Home > Community > Forums > PCB SKILL > SKILL code to detect empty cells while parsing CSV file

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 SKILL code to detect empty cells while parsing CSV file 

Last post Mon, Jun 30 2014 9:23 PM by BinduSripad. 2 replies.
Started by BinduSripad 30 Jun 2014 08:50 PM. Topic has 2 replies and 792 views
Page 1 of 1 (3 items)
Sort Posts:
  • Mon, Jun 30 2014 8:50 PM

    SKILL code to detect empty cells while parsing CSV file Reply

    Hi SKILL experts,

    I am trying to parse a CSV file and populate this data into a hash table. The CSV file could possibly have empty cells. If any of the first 7 columns for a given row in the CSV file is empty, the parser should stop and not write the data to the hash table.

    Although when the line is read from the CSV file and written to a list, an empty cell is recognized as highlighted below:

     before parsing :"PCB Rules, SilkScreen Checks,SilkText to Exposed Pad Spacing,,Text to exposed ViaPad Spacing on Top Layer,axlformbmp1.bmp,silktxt_exposed-spacing.txt,MIN_TXT_TO_VIAPAD_TOP_DIST,FLOAT,1,,,"

     

    After parsing the line using parseString(_line “,”) , the output is as follows. The empty cell is not being detected:

     after parsing :("PCB Rules" " SilkScreen Checks" "SilkText to Exposed Pad Spacing" "Text to exposed ViaPad Spacing on Top Layer" "axlformbmp1.bmp" "silktxt_exposed-spacing.txt" "MIN_TXT_TO_VIAPAD_TOP_DIST" "FLOAT" "1")

     My code snippet is as follows. Please let me know of any other string parsing function in SKILL which can detect spaces (empty cells read from CSV file). Or if I can use a combination of comma and spaces (more than 2) as ‘breakCharacters’.

     _returnLine = nil

    _lineCount = 1

    when(_inFile

    while(gets(_newData _inFile)

    when(_newData !="\n" && _lineCount > 1

    _returnLine = ()

    ;; read each line from the csv file into a string

    _textLine = car(parseString(_newData "\n"))

    printf("\nbefore parsing :%L" _textLine)

    ;; parse the string with comma as the separator

    _returnLine = parseString(_textLine ",")

    printf("\nafter parsing :%L" _returnLine)

    ;; read the parsed fields

    _ruleType = nth(0 _returnLine)

    _category = nth(1 _returnLine)

    _workbook = nth(2 _returnLine)

    _ruleFile = nth(3 _returnLine)

    _ruleName = nth(4 _returnLine)

    _bitmap   = nth(5 _returnLine)

    _document = nth(6 _returnLine)

    ;; populate the hash table only if the first 7 columns for each row are not empty

    if( (_ruleType != " ") then

    if( (nth(1 _returnLine) != " ") then

    if( (nth(2 _returnLine) != " ") then

    if( (nth(3 _returnLine) != " ") then

    if( (nth(4 _returnLine) != " ") then

    if( (nth(5 _returnLine) != " ") then

    if( (nth(6 _returnLine) != " ") then 

    _rule->ruletype = nth(0 _returnLine)

    _rule->category = nth(1 _returnLine)

    _rule->workbook = nth(2 _returnLine)

    _rule->ruleFile = nth(3 _returnLine)

    _rule->ruleName = nth(4 _returnLine)

    _rule->bitmap   = nth(5 _returnLine)

    _rule->document = nth(6 _returnLine)

    )

    )

    )

    )

    )

    )

    )

    ;; insert this structure into hash table with rule name as key

    ruleTable[nth(4 _returnLine)] = _rule

    );when

    ;; move to next line

    _lineCount = _lineCount + 1

    );while

    close(_inFile)

    );when

     

     

    Thanks,

    Bindu 

    • Post Points: 20
  • Mon, Jun 30 2014 8:57 PM

    • eDave
    • Top 10 Contributor
    • Joined on Sun, Jul 13 2008
    • Christchurch, 00-NZ
    • Posts 738
    • Points 16,055
    Re: SKILL code to detect empty cells while parsing CSV file Reply
    axlStringCSVParse has been provided for exactly this reason.
    Dave Elder, Tait Communications
    • Post Points: 20
  • Mon, Jun 30 2014 9:23 PM

    Re: SKILL code to detect empty cells while parsing CSV file Reply

    Thanks for the quick response, Dave!!  Yes, 'axlStringCSVParse' works perfect.

    • Post Points: 5
Page 1 of 1 (3 items)
Sort Posts:
Started by BinduSripad at 30 Jun 2014 08:50 PM. Topic has 2 replies.