File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem With Algorithm Involving Recursion and String Manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem With Algorithm Involving Recursion and String Manipulation" Watch "Problem With Algorithm Involving Recursion and String Manipulation" New topic
Author

Problem With Algorithm Involving Recursion and String Manipulation

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

I thought this will be a good forum to have some fun with an algorithm involving recursion and String manipulation. I was writing an Html unescape algorithm in Java today. What I came out with is the one below. There is a problem in the algorithm below that eats up some space or characters for some corner cases. Can you figure out what the problem is?

I wrote the class in a way so that you can compile and run it in command prompt and can see the output right away. You can do some trial and error and figure out the issue in the algorithm below. If you can please, let me know so that I know exactly where I am going wrong.



Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 158
Few typos/mistakes are corrected, now your code looks as follows: and the output is:
Finally: Ashik's Quote <Test Ok = Ashik's Quote ><Test Ok
-----------
Finally: M& M > 5 = M& M > 5
-----------
Finally: M & M > 5 = M & M > 5
-----------
Finally: M &M > 5 = M &M > 5
-----------
Finally: M& M> 5 = M& M> 5
-----------
Also:
-->Apos'trophie & "quote" is <present>
-----------
Also:
-->Please check for empty space in Order Review tab.
-----------
Also:
-->Also check for Billing Information & Subscription Information & Order Review tabs.
-----------
Also:
-->It's difficult to check today's capitalization strategy for all tabs.
-----------
Also:
-->Remember that 12 is > 9 is > 4
-----------
Also:
-->Similarly 8 is < 10 is < 15
-----------
Also:
-->Shakespeare said,"To be or not to be that is the question."
-----------
Also:
-->Think & think about New York's <best pizza> as the "ultimate" pizza!
-----------
Also:
-->Apos'trophie & "quote" is <present>
-----------
I didn't get you what you are expecting the output to be?


R6i
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

I see the problem here. JavaRanch is converting or escaping the characters that I wanted to escape through coding. I thout the

I did not want to add the same character twice. Instead one of these two will be & # 6 0 ; and the other will be & l t ; (keeping space for each character but there will be so space and those should be treated as one string). Same for all the others.

I tried to attach the source code but the forum is not allowing .java, .htm, .txt, .abc extension files. So I don't know how I can attach the file itself.

By the way, I believe the problem in logic is around these 2 lines.

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

I am attaching 2 GIF images one by one that has the source code. I am not sure if it will be enough for understanding but it will show you the different between the code posted and what I actually wrote.



[Thumbnail for StringUtils Page 1.gif]

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

And here is the second page where the main() is written. Please see if this helps to describe the problem.



[Thumbnail for StringUtils Page 2.gif]

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
It would be much better if you posted properly indented code using CODE tags instead of posting screenshots - much more likely that people will actually read it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem With Algorithm Involving Recursion and String Manipulation