Here you can find the source of singleQuotedString(String str)
public static String singleQuotedString(String str)
//package com.java2s; //License from project: Open Source License public class Main { public static String singleQuotedString(String str) { StringBuilder result = new StringBuilder("'"); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (ch == '\n') { result.append("\\n"); continue; }/*from w ww . j av a2 s . c o m*/ if (ch == '\r') { result.append("\\r"); continue; } if (ch == '\t') { result.append("\\t"); continue; } if (ch == '\'' || ch == '\\') result.append('\\'); result.append(ch); } result.append("'"); return result.toString(); } }