I Have a CSV file stored locally on a Web server which gets added to periodically with numeric and string data all of unequal lengths. I need a way to add up all of the rows byte values from each read, The Byte count is required because of the stateless nature of reading the file in from the server. I need to maintain the next read start point! So far I can get the byte value counted for each row,
function renderData( data )
{
var dataRows = data.split( "\n" );
var numrows = dataRows.length;
var table = document.createElement("Table");
table.border = 1;
var nextindex = 0;
for( i = 0; i < numrows; i++ )
{
var rowlength = dataRows[i].length;
var totalBytes = numrows += rowlength;
currentindex = nextindex;
nextindex = totalBytes;
document.write(" Row "+i+" is " + rowlength + " bytes long ");
document.write(" next index starts " + totalBytes + " bytes in ");
var tableRow = table.insertRow(i);
var dataCells = dataRows[i].split(",");
for( j = 0; j <dataCells.length; j++ )
{
var tableCell= tableRow.insertCell(j);
tableCell.innerHTML = dataCells[j];
}
executeSql( "INSERT INTO CAN ("", "", "", etc) values(?,?,?,)", dataCells );
}
document.body.appendChild( table );
}
How about instead of doing
var totalbytes = numrows*nextindex, make totalbytes a global variable and dototalbytes += rowlength;each iteration ?