ChStr.java~4~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:1k
- package com.core;
- public class ChStr {
- public static String toChinese(String strvalue) {
- try {
- if (strvalue == null) {
- return "";
- } else {
- strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
- return strvalue;
- }
- } catch (Exception e) {
- return "";
- }
- }
- //对输入的字符串进行一次编码转换,防止SQL注入
- public static String StringtoSql(String str) {
- str = nullToString(str, "");
- try {
- str = str.trim().replace(''', (char) 1);
- } catch (Exception e) {
- return "";
- }
- return str;
- }
- //对字符串进行二次编码转换,防止出库时异常
- public static String SqltoString(String str) {
- str = nullToString(str, "");
- try {
- str = str.replace( (char) 1, ''').trim();
- } catch (Exception e) {
- return "";
- }
- return str;
- }
- //对字符串进行Unicode编码
- public static String toUnicode(String strvalue) {
- try {
- if (strvalue == null) {
- return null;
- } else {
- strvalue = new String(strvalue.getBytes("GBK"), "ISO8859_1");
- return strvalue;
- }
- } catch (Exception e) {
- return "";
- }
- }
- //处理字符串中的空值
- public static final String nullToString(String v, String toV) {
- if (v == null || "".equals(v)) {
- v = toV;
- }
- return v;
- }
- }