www.webdeveloper.com
Results 1 to 3 of 3

Thread: Storing the contents of a text file within a variable

  1. #1
    Join Date
    Oct 2005
    Posts
    72

    Question Storing the contents of a text file within a variable

    As a rookie in the world of ASP I was looking for a method to store the contents of text file within a variable. I am so far able to read a text file and output the results. Going a step further I also wanted to replace a particular string within those same results using the "Replace" function. This much works as well, but only when it is written to the screen. My question, how can I store the final result within a variable so that I can reference it later.

    The working code I am using now, is as follows:
    Code:
    <%
    
    Set fs=Server.CreateObject("Scripting.FileSystemObject")
    Set f=fs.OpenTextFile(Server.MapPath("junk.txt"), 1)
    
    do while f.AtEndOfStream = false
    response.write(Replace(f.ReadLine, "________", "12345"))
    Response.Write("<br>")
    loop
    
    f.Close
    
    Set f=Nothing
    Set fs=Nothing
    %>

  2. #2
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    Code:
    <%
    
    Set fs=Server.CreateObject("Scripting.FileSystemObject")
    Set f=fs.OpenTextFile(Server.MapPath("junk.txt"), 1)
    
    'read everything out of the file
    content = f.readall()
    
    'replace the underscores
    content = replace(content, "________", "12345")
    
    'replace the carriage returns with html breaks (not sure if you really want this here or where it gets output).
    content = replace(content,chr(13),"<br>")
    
    f.Close
    
    Set f=Nothing
    Set fs=Nothing
    
    
    response.write content
    
    %>

  3. #3
    Join Date
    Oct 2005
    Posts
    72

    Thumbs up

    This is perfect!! Thank you so much! I'd buy you a beer if I could I'm such a newbie, it's pathetic, I know. I basically wanted this so that the content that displays on the screen while the form is being filled out is the same content that gets pushed with with the email ....or if I use a Preview page the content doesn't have to be duplicated. Basically, I'll have just one text file that needs to be updated, no duplicating. I would think this is fairly common, new to me though. Of coarse what isn't in the realm of ASP. Thanks again!

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