-1

I get no credit for the code below. It was found online. It works to open a file but I'd need something to display only certain strings withing a file (i.e)

test = 2000 
radio 1020
webbrowser - 1000
help needed = 2000

I'd need to modify this to display only, for example, help needed = 2000

<script>
function readBlob(opt_startByte, opt_stopByte) {

    var files = document.getElementById('files').files;
    if (!files.length) {
        alert('Please select a file!');
    return;
}

var file = files[0];
var start = parseInt(opt_startByte) || 0;
var stop = parseInt(opt_stopByte) || file.size - 1;

var reader = new FileReader();

// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
  if (evt.target.readyState == FileReader.DONE) { // DONE == 2
    document.getElementById('byte_content').textContent = evt.target.result;
    document.getElementById('byte_range').textContent = 
        ['Read bytes: ', start + 1, ' - ', stop + 1,
         ' of ', file.size, ' byte file'].join('');
  }
};

var blob = file.slice(start, stop + 1);
reader.readAsBinaryString(blob);
  }

 document.querySelector('.readBytesButtons').addEventListener('click', function(evt) {
if (evt.target.tagName.toLowerCase() == 'button') {
  var startByte = evt.target.getAttribute('data-startbyte');
  var endByte = evt.target.getAttribute('data-endbyte');
  readBlob(startByte, endByte);
}
 }, false);
</script>
Nissa
  • 4,589
  • 8
  • 27
  • 37
PCosta
  • 9
  • 1
  • 4
    To be clear, you found code online, copy/pasted it into Stack Overflow and now you're asking us to please rewrite it for you to do what you need? We are not a code writing service - you're expected to do a bare minimum of research and make an attempt at solving your problem before posting a question. – AmericanUmlaut Feb 08 '17 at 04:53
  • can you explain what you want in words? – Sagar V Feb 08 '17 at 04:55

1 Answers1

0

First of all, web browsers does not allow you to access local files using javascript for security reasons.

So, if you really want to read the file in javascript, you should consider setting up an environment to execute javascript. You can read it here. Executing javascript without browser.

Community
  • 1
  • 1
Mohammed Shareef C
  • 2,784
  • 21
  • 33