The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


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

    Code:
    imagepath1/imageA.jpg
    imagepath2/imageB.jpg
    imagepath3/imageC.jpg
    imagepath4/imageD.jpg
    ...
    (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 ?

    thanks

    mlk

    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
    176
    posts
    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>
    <head>
    <title>Behaviors</title>
    <script type="text/javascript">
    function downloadEnd(e) {
    	var s=Array();
    	t='';
    	s=e.split('\n');
    	for(i=0;i<s.length;i++){
    		t+=s[i];
    	}
    	document.all.download.value=t;
    }
    </script>
    <style type="text/css">
    textarea {
    	background-color: #000;
    	color: #FFF;
    	scrollbar-face-color: #FFF;
    }
    </style>
    </head>
    <body>
    <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>
    </body>
    </html>
    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

 Credits

Copyright 1999 - 2012