java对字符串进行数据转换

//对提交的字符串进行非法字符的过滤
public String CheckReplace(String s) {
	try {
		if ((s == null) || (s.equals("")))
			return "";

		StringBuffer stringbuffer = new StringBuffer();
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			switch (c) {
			case '"':
				stringbuffer.append(""");
				break;
			case '\'':
				stringbuffer.append("'");
				break;
			case '|':
				stringbuffer.append("");
				break;
			case '&':
				stringbuffer.append("&");
				break;
			case '<':
				stringbuffer.append("<");
				break;
			case '>':
				stringbuffer.append(">");
				break;
			default:
				stringbuffer.append(c);
			}
		}

		return stringbuffer.toString().trim();
	} catch (Exception e) {
	}
	return "";
}

public String CheckDate(String[] s1, String[] s2) {
	boolean OK = true;
	StringBuffer sb = new StringBuffer();
	try {
		for (int i = 0; i < s1.length; i++) {
			if ((s1[i] == null) || (s1[i].equals("")) || (s1[i].equals(" "))) {
				sb.append("
  • [ " + s2[i] + " ] 不能为空!"); OK = false; } } if (OK) return "Yes"; return sb.toString().trim(); } catch (Exception e) { } return "操作失败!"; } public String getStrCN(String s) { return s; } public int StrToInt(String s) { try { return Integer.parseInt(CheckReplace(s)); } catch (Exception e) { } return 0; } public boolean StringToBoolean(String s) { if ((s != null) && (s.equals("Yes"))) return true; return false; }
  • 你可能感兴趣的:(java)