On this Page

    _parser.delimited

    Convert comma or tab-delimited records.

    Syntax

    _parser.delimited(recordnames[, delimiter[, quote[, trim]]])

    Parameters

    record is the text to be parsed. Trailing newline and carriage returns are ignored (not returned as data).

    names is an array of field names. The record is assumed to have these fields in it in this order. This allows the resulting output to be treated like an array of parsed values. If any individual names array element is set to null rather than a field name, the corresponding data field is excluded from the output, i.e. the field is ignored. If a names parameter is set to null the fields will instead be named 0, 1, ... sequentially.

    delimiter is optional and defaults to ',' (a comma). Set this to '\t' for tab-delimited data records or ' ' for blank-delimited files.

    quote character is optional and defaults to the double-quote character. This is the type of quotation character that surrounds strings in the data stream. You might want to set to "'" to use single-quotes.

    trim parameter is optional (defaults to false). If present and set to true, returned values will have leading as well as trailing blanks removed.

    Returned Value

    The returned value of this function is a JavaScript object whose properties are the names from the names parameter and values are the associated values from the data record. If the record is incorrectly formatted and cannot be parsed, the return value is null.

    Description

    This routine is used to parse a single delimited record and assign names to all the values in that record.

    Example

    var names = ["first", "second", "third", "fourth"];
    var record = '"one","two","three"';
    var obj = _parser.delimited(record, names);
    
    if (obj) {
    	_message("obj.first=%s obj.second=%s", obj.first, obj.second);
    } else {
    	_message("Error parsing line");
    }

    Of course, normally one would have read in a record rather than having it hard-coded. This is equivalent to having set:

    obj.first  = "one";
    obj.second = "two";
    obj.third  = "three";
    obj.fourth = null;

    See Also

    _parser.delimitedToXml
    _parser.fixed
    _parser.fixedToXml
    _parser.parms