将String字符串的英文双引号批量转换成中文双引号

/**
 * 将字符串的英文双引号替换为中文双引号
 * @author 刘仁奎
 */
public class ReplaceString {
	public static void main(String[] args) {
		String str = "\"国家税务总局\"教育中心关于举办\"四川省国税局基层\"领导干部更新知识"智力援西"培训班的通知";
		System.out.println(strReplace(str));
	}

	public static String strReplace(String pStr) {
		// 把字符串按照双引号截成数组
		String[] str = pStr.split("\"");
		// 替换后的字符串
		String Newstr = "";
		for (int i = 1; i <= str.length; i++) {
			if (i % 2 == 0) {
				Newstr += str[i - 1] + "”";
			} else {
				Newstr += str[i - 1] + "“";
			}
		}
		// 拼接
		return Newstr.substring(0, Newstr.length() - 1);
	}
}


你可能感兴趣的:(将String字符串的英文双引号批量转换成中文双引号)