Results 1 to 3 of 3

Thread: Replace a string in textfile

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    76

    Replace a string in textfile

    I am writting table contents into a file .

    The contents have to be as follows:
    <html>
    <body>
    <table>
    <tr>
    <td> SNO</td>
    </tr>
    <tr>
    <td>Name</td>
    </tr>
    </table>

    <table>
    <tr>
    <td>1</td>
    <td>XYZ</td>
    </tr>
    </table>
    </body>
    </html>

    In this I am able to write the first table succesfully. When i write a second table i give the replace option as:
    io.file.replace("</body>","<table></table></body>")

    Now when i read the each row inside the second i need to replace the last "</table>" alone with "<tr></tr></table>"

    When i give replce option, it replaces in every occurances of </table> and so I am getting the row of the second table in the first table also.

    How to find the last occurance of </table> and then replace. Any help in this??????

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Replace a string in textfile

    The last occurence of a string in another string can be found using the "InStrRev()" function.
    I think you can also use the string.LastIndexOf() function (which I think is the .NET equivalent of InStrRev) but I've never tried that...

  3. #3
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Replace a string in textfile

    Why don't you isolate the table writing by itself... in a function of some sort, then when writing out the entire file, you just account for the opening and closing html and body tags in the sub? Shouldn't have to "replace" anything that way...

Posting Permissions

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



Click Here to Expand Forum to Full Width