• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I replace a single quote ( ' ) with two single quotes ( '' )

 
thgiwd
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need help..
How do I replace a single quote ( ' ) with two single quotes ( '' ) ??
 
Raghav Sam
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by thgiwd:
Need help..
How do I replace a single quote ( ' ) with two single quotes ( '' ) ??

Can you be more specific? Where do you want to do it?
 
Rehan Malik
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by thgiwd:
Need help..
How do I replace a single quote ( ' ) with two single quotes ( '' ) ??

I think I know what you're asking. But I'm taking a stab in the dark considering I don't know SPECIFICALLY what is being asked.
I am going to guess that you're trying to insert data into a database and that the single quotes in the text is messing you up.
You have to write a method which will replace the instances of ' with ''.
Here's the algorithm (Specifically for Strings but can be expanded towards other datatypes)
1. Find first index of "SearchString"
2. If first index value does not equal -1 (Continue to step 3, otherwise end search)
3. Use a StringBuffer class to hold the substring from the beginning of the sentence to the index of the first instance of the "SearchString".
4. Append "ReplaceString" to the substring
5. Repeat step 2 starting with original string (plus the length of the searchString).
Good luck
I'd offer the code to do this but then it would be too easy
But if you still have a lot of problems with it, let me know and I'll post it.
 
Dwight See
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks.. i got it already..
i followed your instructions..
thanks again..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!