Java tutorial
//package com.java2s; public class Main { private static String removeSingleQuotes(StringBuffer tempBuffer, int questionSignIndex) { int delRightIndex = tempBuffer.indexOf("'", questionSignIndex); int delLeftIndex = tempBuffer.lastIndexOf("'", questionSignIndex); if (isDelSingleQuotes(tempBuffer, delLeftIndex, delRightIndex)) { tempBuffer.deleteCharAt(delRightIndex); tempBuffer.deleteCharAt(delLeftIndex); } return tempBuffer.toString(); } private static boolean isDelSingleQuotes(StringBuffer tempBuffer, int beginIndex, int endIndex) { if (isWrongIndex(beginIndex, endIndex)) { return false; } if (!"?".equals(tempBuffer.substring(beginIndex + 1, endIndex).trim())) { return false; } return true; } private static boolean isWrongIndex(int beginIndex, int endIndex) { if (-1 == beginIndex || -1 == endIndex) { return true; } if ((beginIndex >= endIndex)) { return true; } return false; } }