SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parsing an ascii text file

    would like to know how or where i can find code to parse a ascii text file. it needs to open the file search for a specified keyword or phrase. if not found the write the line as is, if found the remove the target and wrte the rest of the line with out the target.

    example:

    open file test1.txt
    look for : http

    sample:

    first
    second
    note: http..........
    third
    fourth

    output file: test2.txt

    first
    second
    note:
    third
    fourth

    lines can be small or large


    thanks....

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jbetts1967 View Post
    would like to know how or where i can find code to parse a ascii text file. it needs to open the file search for a specified keyword or phrase
    That can be done by reading the file in to a variable, and then using string-searching methods to look for what you want within that string.

    An example of reading a file can be found in the Bulletproof Ajax book.
    Their website makes all of the code freely available. In this cast it's from their Chapter 3 example, and the file that contains the Ajax code is in:
    http://bulletproofajax.com/code/chap...st/ajaxtest.js

    You would just need to remove the displayResponse function and instead return the result, so that you can assign it to a variable.

    var content = grabFile(location);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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