0

I'm trying to develop an app which needs to parse a text file (either remotely hosted or bundled with the app) and show the users certain data based on their criteria. I have been trying to find information about how to parse a text file, but I can't find anything.

Would anybody please help here?

Thanks a lot in advance!

noloman
  • 11,411
  • 20
  • 82
  • 129
  • What do you mean by parse? Do you really have a grammar and want to parse the string using it? There's [PEG.js](http://pegjs.majda.cz/) for that. – Ricardo Panaggio Nov 06 '13 at 22:48
  • I want to have a document in the phone (or internet) and being able to read the document and extract certain parts of it, and show it to the user. – noloman Nov 07 '13 at 16:58
  • So what is your specific issue? Reading the file? Extracting the information? You should clarify your question. – Ricardo Panaggio Nov 09 '13 at 01:40
  • Are you using any specific format, or is it to be defined? For instance, if the file you're willing to parse is a JSON file, it's trivial. Clarify what you don't know how to do, please, so that we can help more. – Ricardo Panaggio Dec 26 '13 at 12:17

1 Answers1

0

Not sure this is what you are looking for but one solution would be to use the SystemXHR request:

var picktxt = document.querySelector("#pick-txt");
if (picktxt) {
    picktxt.onclick = function () {

    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'txt/huckfinn.txt');
    xhr.responseType = 'text';
    xhr.onload = function() {                
        var newlines = this.responseText.split( "\n" );
        alert( newlines.length );
        alert( newlines[50] );
    };
    xhr.onerror = function() {
        console.log('Error reading txt file');
    };
    xhr.send();

    }
}

A little around the elbow but should work

Jason Weathersby
  • 1,071
  • 5
  • 5