Replace Text in a Text File

Results 1 to 2 of 2

Thread: Replace Text in a Text File

  1. #1
    Join Date
    Dec 1969
    Posts
    237

    Default Replace Text in a Text File

    I have a Text file and need to replace some data in each line (Row Length is 55) from this Text File. Need to Replace Data from Position 11-19 on each Row, - 9 digits with something else like 123456789 (some random nos).

    Please help me with code

    <%
    Set fs=Server.CreateObject("Scripting.FileSystemObject ")

    Set f=fs.OpenTextFile(Server.MapPath("MyTextFile.txt") , 1)



    f.Close
    Set f=Nothing
    Set fs=Nothing
    %>

  2. #2
    Join Date
    Dec 1969
    Posts
    95,971

    Default

    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=133

    So you have no choice but to read from one file and write to another.
    And just use string manipulation to change the line contents.

    example:
    Code:
    line = fromFile.readLine
    front = Left(line,10)
    back = Mid(line,20)
    line = front & "123456789" & back
    toFile.writeLine line
    And do that in a loop for the entire file.

Posting Permissions

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


More ASP Resources

Resources:
-- ASP Articles
-- ASP.NET Information
-- 4Guys ASP F.A.Q.
-- ASPFAQs.com
-- ASP Coding Tips
-- Related Web Technologies
-- User Tips!!
-- JavaScripts


Development Centers
-- HTML5 Development Center
-- Windows Mobile Development Center
-- Android Development Center
-- Cloud Development Project Center


Development Technology
Check out these sites for more articles, tutorials, FAQs, discussions, and code!
-- CodeGuru.com
-- VBForums.com
-- DevX.com
-- Developer.com
-- HTMLGoodies