www.webdeveloper.com
Results 1 to 4 of 4

Thread: reading txt file

  1. #1
    Join Date
    Mar 2009
    Posts
    13

    reading txt file

    Hi friends,

    i have a txt file containing email id's like
    test.txt
    asdf@gmail.com
    qwer@gmail.com
    zxcv@gmail.com

    when user imports test.txt file i want to get the all email id's by comma seperated value... using javascript
    asdf@gmail.com,qwer@gmail.com,zxcv@gmail.com ....
    like this
    how can i??
    help me plzzz...

  2. #2
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    i don't know how you are reading such file but assuming you read the file as a string, you can split each id by character space and then join them with comma:
    Code:
    // assuming file is the imported test.txt file;
    emails = file.split(/\s+/).join(',');
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  3. #3
    Join Date
    Jan 2008
    Posts
    123
    I actually did this not too long ago. You will need jQuery.

    my .txt looks like this:

    Code:
    product=DeepOcean&build=35&date=2009_03_12&time=20_06_21&location=RLLOYD_laptop&sponsor0=TheRideWorks&rideTime=229&maxDepth=27&photoFolder=RLLOYD_laptop__2009_03_12__20_06_21&numPhotos=6&photoFile0=pic1.jpg&photoCaptionID0=13000&photoCaption0=42617420526179&photoDepth0=24&photoSpecies0=13000&photoFile1=pic2.jpg&photoCaptionID1=24007&photoCaption1=43616c69666f726e696120536561204c696f6e205377696d6d696e67&photoDepth1=18&photoSpecies1=13013&photoFile2=pic3.jpg&photoCaptionID2=13041&photoCaption2=53756e666c6f7765722053746172&photoDepth2=18&photoSpecies2=13041&photoFile3=pic4.jpg&photoCaptionID3=13009&photoCaption3=43616c69666f726e696120487964726f636f72616c&photoDepth3=8&photoSpecies3=13009&photoFile4=pic5.jpg&photoCaptionID4=13031&photoCaption4=576f6c662045656c&photoDepth4=26&photoSpecies4=13031&photoFile5=pic6.jpg&photoCaptionID5=13018&photoCaption5=42756f79&photoDepth5=0&photoSpecies5=13018&allBehaviors=13018-13005-13041-0-24007-13031-13009-13000
    and the JS/jQ looks like this:

    Code:
    $.get("form_data.txt", function(data){
      var queryString = data;
      var queryArray = queryString.split('&');
      
       if (!queryArray[queryArray.length - 1])
        	queryArray.pop();
     
      for (var index = 0; index < queryArray.length; ++index) {
        		var item = queryArray[index].split('=');
       			eval('var ' + item[0] + '="' + item[1] + '"');
    			}
    Hope this helps,

    --thesprucegoose

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by thesprucegoose View Post
    I actually did this not too long ago. You will need jQuery.
    Do you think JQuery uses other language than javascript? Simple problems need simple solutions.

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
  •  
HTML5 Development Center



Recent Articles