File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem With Algorithm Involving Recursion and String Manipulation

 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
M K Rayapudi
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
StringUtils Page 1.gif
Source Code of StringUtils.java page 1
[Thumbnail for StringUtils Page 1.gif]
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And here is the second page where the main() is written. Please see if this helps to describe the problem.
StringUtils Page 2.gif
Source Code of StringUtils.java page 2
[Thumbnail for StringUtils Page 2.gif]
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic