In Java I have:
String str = "Welcome 'thanks' How are you?";
I need to replace the single quotes in str by \', that is, when I print str I should get output as Welcome \'thanks\' How are you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It looks like perhaps you want something like this:
This uses
String.replace(CharSequence, CharSequence)method to do string replacement. Remember that\is an escape character for Java string literals; that is,"\\'"contains 2 characters, a backslash and a single quote.References