码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA编码字符串和解码字符串

时间:2016-05-25 16:33:57      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

1.编码字符串

public static String encode(String s, String encodeType) {
		if (s == null || s.equals("")) {
			return "";
		}
		if (encodeType == null || encodeType.equals("")) {
			return s;
		}
		try {
			return URLEncoder.encode(s, encodeType);
		} catch (Exception e) {
		}
		return s;
	}

2.解码字符串

public static String decode(String s, String encodeType) {
        if (s == null || s.equals("")) {
            return "";
        }
        if (encodeType == null || encodeType.equals("")) {
            return s;
        }
        try {
            s = URLDecoder.decode(s, encodeType);
        } catch (Exception e) {
        }
        return s;
    }

 

JAVA编码字符串和解码字符串

标签:

原文地址:http://www.cnblogs.com/chenchaochao/p/5527292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!