Replace Until Loop in HTML

Replace Until Loop in HTML

2
NewbieNewbie
2

    Apr 15, 2005#1

    I can't quite figure this one out and was hoping for some help.

    Situation: HTML file lists information sorted alphabetically. Each letter of the alphabet is it's own table. The rows of info have alternating color backgrounds.

    Problem 1: When new information has to be added, a new TR is created in the middle of the table, forcing me to rename the alternating colors for the whole table.

    Very Short Sample HTML:

    Code: Select all

    <a name="c">C</a>
    <table cellpadding="1" cellspacing="0" border="0" width="100%">
    <tr class="color1"><td>C Info 1</td></tr>
    <tr class="color2"><td>C Info 2</td></tr>
    <tr class="color1"><td>C Info 3</td></tr>
    <tr class="color2"><td>C Info 4</td></tr>
    </table>
    
    Here is the Macro that I made that ALMOST does the job:

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    Find "<tr class="color2"><td>"
    Replace All SelectText "<tr class="color1"><td>"
    Find " class="color1""
    Find " class="color1""
    Replace "class="color2""
    
    Problem 2: Each letter is it's own table and the first row of each table needs to be color1. With this macro, every other row is replaced throughout the whole file. Resulting in:

    Code: Select all

    <a name="c">C</a>
    <table cellpadding="1" cellspacing="0" border="0" width="100%">
    <tr class="color1"><td>C Info 1</td></tr>
    <tr class="color2"><td>C Info 2</td></tr>
    <tr class="color1"><td>C Info 3</td></tr>
    </table>
    
    <a name="d">D</a>
    <table cellpadding="1" cellspacing="0" border="0" width="100%">
    <tr class="color2"><td>D Info 1</td></tr>
    <tr class="color1"><td>D Info 2</td></tr>
    <tr class="color2"><td>D Info 3</td></tr>
    </table>
    
    When what I really need is for the first row of the D table to start as color1.

    I don't know if UE does this, but I was thinking along the lines of:
    Loop from "<table"
    Do the Find and Replace
    Until "</table>"
    Repeat until EoF

    Can any of the experts here help me out? Thanks! :D

    261
    Basic UserBasic User
    261

      Apr 15, 2005#2

      Well I don't know if I'd call myself an expert, but I think you could do this:

      Find each table definition, copy it to a new file, run your macro on it, then copy it back. Here's a macro that seems to work:

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Clipboard 9
      Top
      Loop
      Find "<table"
      IfNotFound
      ExitLoop
      EndIf
      Find Select "</table>"
      IfNotFound
      ExitLoop
      EndIf
      Copy
      NewFile
      Paste
      PlayMacro 1 "altColors"
      SelectAll
      Copy
      CloseFile NoSave
      Paste
      EndLoop
      Clipboard 0

      The macro "altColors" refers to your original macro. I had to modify it a little to get it to work for me, though. This is what I ended up with:

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Top
      Find "<tr class="color2"><td>"
      Replace All "<tr class="color1"><td>"
      Top
      Loop
      Find "<tr class="color1"><td>"
      IfNotFound
      ExitLoop
      EndIf
      Key RIGHT ARROW
      Find "<tr class="color1"><td>"
      Replace "<tr class="color2"><td>"
      IfNotFound
      ExitLoop
      EndIf
      Key RIGHT ARROW
      EndLoop

      I'm sure there are ways to improve these, but this is all the time I have right now.

      Good Luck!

      Dave
      ASTTMan
      I'm not a Texan, I just live here.

      2
      NewbieNewbie
      2

        Apr 15, 2005#3

        Outstanding work! Thank you. It works very well. The whole select the table and paste it into a temp file was genius! Thanks again! :D