I have develop an app in HTML5 and JS (phonegap) and now I have to read a text file as an export from an old desktop application written in delphi. This file is an MS SQL export with fixed size strings that i have to import to SQlite of my app.
This text contains Greek Characters and is not encoded in UTF so I read diamonds with questionmarks.
Is there a way to encode this text to UTF programmatically before i read the contents???
It is forbiten to change any delphi code.
This is how I read the text file
var billjson = '{"posts" : [',
i,
line = 0,
Amountint,
Amountdec;
jQuery.get('Bill.txt',function(data){
alert(data.length);
line=0;
for (i = 1; i <= ((data.length)/156); i += 1) {
billjson += '{"Id" :' + '"' + data.substr((line+0), 10).trim() + '"' + ',';
billjson += '"Code" :' + '"' + data.substr((line+10), 5).trim() + '"' + ',';
billjson += '"Address" :' + '"' + data.substr((line+14), 40).trim() + '"' + ',';
billjson += '"Name" : ' + '"' + data.substr((line+54), 50).trim() + '"' + ',';
billjson += '"Description" : ' + '"' + data.substr((line+104), 8).trim() + '"' + ',';
billjson += '"EntrySeason" : ' + '"' + data.substr((line+112), 23).trim() + '"' + ',';
billjson += '"Period" : ' + '"' + data.substr((line+135), 11).trim() + '"' + ',';
Amountint = data.substr((line+146), 7).trim();
Amountdec = data.substr((line+153), 2).trim();
billjson += '"Revenue" : ' + '"' + Amountint + '.' + Amountdec + '"' + '}';
line = i * 156;
if (line == data.length)
{
billjson += ']';
}
else
{
billjson += ',';
}
}
if (line == 0)
{
billjson += ']';
}
billjson += "}";
var mybilljson = jQuery.parseJSON( billjson );
});
Please advice
You have to let jquery know what encoding is used in the file it’s loading.