Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 3 of 3

Thread: parse text file using JS

  1. #1

    parse text file using JS

    Hello little kirupians, here's a little question for you:

    I have a text file, written in such way

    (the .txt is actually 1Mib large)

    Can I parse this text file in an html page using javascript, so each line belongs to an array ? Using split works for characters, but could it work with the linebreak ?



    ps: if anyone knows a way to declare a large chunk of text as a variable (I can't seem to be able to use multi-line variable withouth writing '\' at the end of each line), it would help me greatly !

  2. #2
    Registered User
    I found a sample online ... and edited a bit for our purposes. This reads from a file 'images.txt' on the same directory as the file. Gets the text as a variable and then splits it.

    HTML Code:
    <html xmlns:behave_yaself>
    <script type="text/javascript">
    function downloadEnd(e) {
    	var s=Array();
    <style type="text/css">
    textarea {
    	background-color: #000;
    	color: #FFF;
    	scrollbar-face-color: #FFF;
    <behave_yaself:download id="currFile" style="behavior:url(#default#download);" />
    Click <a href="javascript:document.getElementById('currFile').startDownload('images.txt',downloadEnd)">here</a>
    to start the download. 
    <br />When the download is finished, the text will be displayed in the <b>TEXTAREA</b> below.
    <p><textarea rows="20" cols="40" id="download"></textarea></p>
    PHP Code:
    <zip> echo this; </zip

  3. #3
    thanks, I'll look into it !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012