|
-
Sep 11th, 2006, 07:42 AM
#1
Thread Starter
New Member
[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.
-
Sep 11th, 2006, 12:02 PM
#2
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.
-
Sep 11th, 2006, 03:07 PM
#3
Frenzied Member
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|