• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Question on for loop

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the code below I have a ByteArrayOutputStream that I'm trying to loop through and the objective is trying to REPLACE the HTML equivalent (&) with the "&" character itself. The issue that I'm trying to correct is that the & value is being printed in a log and I need to correct that with "&". The code below is what I've attempted but this is NOT working.

Any help would be appreciated. Thanks.

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just in case someone else wanted to see what the answer was. Please see fix below. I also added other HTML codes I needed to fix. Thanks anyway. This came from another poster Ben from StackOverflow.com.

 
Marshal
Posts: 79828
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done working it out. Remember the real reason: Strings are immutable, so you get the changed version as the return value. That is what you need to keep. If you don't assign the return value to something, it disappears into cyber‑limbo never to be seen again.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the info Campbell. I appreciate the info.
 
Campbell Ritchie
Marshal
Posts: 79828
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome That is a common pitfall. You get the same problems with things like BigDecimal for the same reason.
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic