Results 1 to 3 of 3

Thread: [JAVA] Find and replace

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    1

    [JAVA] Find and replace

    When I was making a picture site, I ran to the next problem:

    When I host my pictures through a free host like imageshack, I get a heap of HTML code. This code places all the image behind eachother which isn't good for the layout of my site. That's why I'm busy with a very simple applet that changes this html. The applet has to do this:


    1. the original code needs to be pasted in a first textfield
    2. find and remove "<p>" and "</p>"
    3. find "<a href=" and replace by "<td><a href="
    4. find "alt="" /></a>" and replace by "alt="" /></a></td>"
    5. find "<td>" and the 3 time, replace by "<tr><td>"
    6. find "</td>" and the 3 time, replace by "</tr></td>"
    7. find "<tr>" and the 3 time, replace by "<table border="0"><tbody><tr>"
    8. find "</tr>" and the 3 time, replace by "</tr></tbody></table>{mospagebreak}<br />"
    9. give the output in a second textfield, ready to copy/past on the site.

    Like this the pictures get organised in a table of 3 on 3 and after each table there is a code that generates a new page. All the normal find and replace i can do, but it's the ones that only replace the third time that i can't find. I've been looking on google and in the java documentation but I can't find anything useful.

    For you guys this must be a peace of cake, that's why I'm asking it here.

    Tnx.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: [JAVA] Find and replace

    It's not at all a piece of cake. It's error-prone and extremely boring but time-consuming text replacement.

    Look into the java.util.regex package.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: [JAVA] Find and replace

    As CB said, this is very error prone, especially if it's real world.

    For instance, take this 'rule':

    Code:
    3. find "<a href=" and replace by "<td><a href="
    What happens if the code turns out to be:

    Code:
    <b><a href="
    It may end correctly, but your code probably won't be formatted like you want. Several other more serious complications 'could' happen, but that's just one of many simple scenarios.

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