• Hello and welcome to MSFC. We are a small and close knitted community who specialises in modding the game Star Trek Armada 2 and the Fleet Operations modification, however we have an open field for discussing a number of topics including movies, real life events and everything in-between.

    Being such a close community, we do have some restrictions, including all users required to be registered before being able to post as well as all members requiring to have participated in the community for sometime before being able to download our modding files to name the main ones. This is done for both the protection of our members and to encourage new members to get involved with the community. We also require all new registrations to first be authorised by an Administrator and to also have an active and confirmed email account.

    We have a policy of fairness and a non harassment environment, with the staff quick to act on the rare occasion of when this policy is breached. Feel free to register and join our community.

Need Help coding html5.

CrazyFrog1903

Boba Frog!
Joined
25 Apr 2006
Messages
1,860
Is there anyone on here that knows how to call information from a CSV file using Javascript in HTML5? I really don't want to hard code 30 pages and if I can pull information it would be easier. Can't do a database because the company I am doing it for may not have the same type. Thanks
 

Hellkite

Lord of Death
Staff member
Administrator
Seraphim Build Team
Star Fighter
Joined
23 Apr 2006
Messages
7,648
Here is the modification :

function parseLineCSV(lineCSV) {
// parse csv line by line into array
var CSV = new Array();

// Insert space before character “,”. This is to anticipate ‘split’ in IE
// try this:
//
// var a=”,,,a,,b,,c,,,,d”;
// a=a.split(/\,/g);
// document.write(a.length);
//
// You will see unexpected result!
//
lineCSV = lineCSV.replace(/,/g,” , “);

lineCSV = lineCSV.split(/,/g);

// This is continuing of ‘split’ issue in IE
// remove all trailing space in each field
for (var i=0;i<lineCSV.length;i++) {
lineCSV = lineCSV.replace(/\s*$/g,””);
}

lineCSV[lineCSV.length-1]=lineCSV[lineCSV.length-1].replace(/^\s*|\s*$/g,””);

var fstart = -1;
//MODIFICATION START
var quotedStr = false;
var endQuotedStr = false;

for (var i=0;i<lineCSV.length;i++) {
//if we start a quoted string
if(!quotedStr && lineCSV.match(/^\s*”/))
{
quotedStr = true;
fstart = i;
}
//if we are going out of a quoted string
if(quotedStr && lineCSV.match(/”\s*$/))
{
endQuotedStr = true;
}
//if this piece of string is inside the quoted string and it is not the first part
// do concatenation
if (quotedStr && fstart < i){
lineCSV[fstart]=lineCSV[fstart]+”,”+lineCSV;
lineCSV=”-DELETED-“;
}
//we are out of this quoted string, resets default values
if(endQuotedStr)
{
quotedStr = false;
endQuotedStr = false;
fstart = -1;
}
}
//MODIFICATION END

var j=0;
for (var i=0;i<lineCSV.length;i++) {
if (lineCSV!=”-DELETED-“) {
CSV[j] = lineCSV;
CSV[j] = CSV[j].replace(/^\s*|\s*$/g,””); // remove leading & trailing space
CSV[j] = CSV[j].replace(/^”|”$/g,””); // remove ” on the beginning and end
CSV[j] = CSV[j].replace(/””/g,'”‘); // replace “” with ”
j++;
}
}

return CSV;
}
 
Top