:: Forum >>

Escape a comma in a CSV table?


Hi...

My data contains commas, and I can't use XML. Is there any way I can escape the comma so it will appear inside the grid?
Shawn Kelly
Monday, November 13, 2006
Hmm... in IE ",," seems to work. But in FF (and common sense) ",," is two fields. Common sense would dictate that putting quotes around a comma-containing text would do the trick.

I guess I'll have to hack the grid or something? No one came across this before?
Shawn Kelly
Monday, November 13, 2006
The examples in the examples\old directory seem to work fine and they contain commas.
Its just enclosed in quotes - here's a line from the data file:

MSFT,"Microsoft Corporation","314,571.16","32,187.00",55000

I'm Not sure if I'm misunderstanding your question as I use plain javascript arrays as input.
I've never needed to use csv.

Ankur
Ankur Motreja
Monday, November 13, 2006
Yea.. I'm using a CSV table.
Shawn Kelly
Monday, November 13, 2006
If the field text contains comma you should put quotes around the field. I could not reproduce the problem which you describe with FF, however the current parsing code does have problems in some cases. Here is the patch with a better parsing algorithm which solves most of them (except multiline fields) -

(function(){

    new AW.CSV.Table;

    var x1 = /(([^,\t\"]*)|\"(([^\"]|\"\")+)\")(,|\t|$)/g;
    var x2 = /\"\"/g;
    var s1 = "$2$3\x01";
    var s2 = "\"";
    var s3 = "\x01";

    AW.CSV.Table.prototype.getData = function(c, r){

        if (!this._data[r]){
            if (!this._rows[r]){return ""}
            this._data[r] = this._rows[r].replace(x1, s1).replace(x2, s2).split(s3);
        }

        return this._data[r][c] || "";
    }

})();

Alex (ActiveWidgets)
Monday, November 13, 2006

This topic is archived.


Back to support forum

Forum search