Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String replace function with single quote

 
Dean Reedy
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is I understand how a replace function works with the Strings. My problem is I have string with single quotes ', and I need to change them to two single quotes '', because I need to insert them into a database. How can I do this using the replace function.
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can try to use the escape character like so "\'".
Let me know if this works
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The replace function in String only works with single characters. You can use a better replace function such as the one that I've written in my StringHelper:
http://ostermiller.org/utils/StringHelper.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic