Method 1: Using the replaceALL
String myInput = "\"data1\",\"data2\",\"data3\",\"data4\",\"data5\""; String myOutput = myInput.replaceAll("\"", "'"); System.out.println("My Output with Single Quotes is : " +myOutput);
Output:
My Output with Single Quotes is : 'data1','data2','data3','data4','data5'
Method 2 : use Pattern.compile
import java.util.regex.Pattern; String myInput = "\"data1\",\"data2\",\"data3\",\"data4\",\"data5\""; String myOutputWithRegEX = Pattern.compile("\"").matcher(myInput).replaceAll("'"); System.out.println("My Output with Single Quotes is : " +myOutputWithRegEX);
Method 3 : Using Apache Commons , as defined in the link below:
http://commons.apache.org/proper/commons-lang/javadocs/api-z.1/org/apache/commons/lang3/StringUtils.html
Nishanthi Grashia Aug 12 '14 at 7:18 2014-08-12 07:18
source share