Forums Register Login

Problem With Algorithm Involving Recursion and String Manipulation

+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
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]
+Pie Number of slices to send: Send
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]
+Pie Number of slices to send: Send
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 think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2253 times.
Similar Threads
Using JDBC how to put single quotes(')
I tried run this double recurrences unsuccessfully, can you help run it
Knuth Morris Pratt Search Algorithm Help
Dan Question - doubt
LinkedHashMap - trying to use the method removeEldestEntry
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:28:44.