forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChStr.java
More file actions
37 lines (35 loc) · 1.14 KB
/
ChStr.java
File metadata and controls
37 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.core;
public class ChStr {
public static String toChinese(String strvalue) {
try {
if (strvalue == null) { //当变量strvalue为null时
strvalue=""; //将变量strvalue赋值为空
} else {
strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK"); //将字符串转换为GBK编码
strvalue = strvalue.trim(); //去除字符串的首尾空格
}
} catch (Exception e) {
strvalue=""; //将变量strvalue赋值为空
}
return strvalue; //返回转换后的输入变量strvalue
}
// 处理字符串中的空值
public static final String nullToString(String v, String toV) {
if (v == null || "".equals(v)) { //当输入变量v为空时
v = toV; //将输入变量v赋值为输入变量toV
}
return v; //返回转换后的输入变量v
}
//过滤危险字符
public static final String filterStr(String str){
str=str.replaceAll(";","");
str=str.replaceAll("&","&");
str=str.replaceAll("<","<");
str=str.replaceAll(">",">");
str=str.replaceAll("'","");
str=str.replaceAll("--"," ");
str=str.replaceAll("/","");
str=str.replaceAll("%","");
return str;
}
}