您的位置:首页 > 其它

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

2013-03-11 13:41 316 查看
/**
 * 将字符串的英文双引号替换为中文双引号
 * @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);
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐