Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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: 74634
335
  • 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: 74634
335
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic