📄 util.java
字号:
package com.laoer.bbscs.util;
import java.util.*;
import java.text.*;
import java.io.*;
import com.laoer.bbscs.sysinfo.*;
public class Util {
public Util() {
}
/*
public static void log(String logMsg) {
Date myDate = new Date();
try {
BufferedWriter out = new BufferedWriter(new FileWriter(Sys.SYSINFO.SYSLOG, true));
out.write(logMsg + " [" + fotmatDate1(myDate) + "]\n");
out.close();
}
catch (IOException e) {
//System.out.println(e.getMessage());
}
}*/
public static String[] split(String source, String div) {
int arynum = 0, intIdx = 0, intIdex = 0, div_length = div.length();
if (source.compareTo("") != 0) {
if (source.indexOf(div) != -1) {
intIdx = source.indexOf(div);
for (int intCount = 1; ; intCount++) {
if (source.indexOf(div, intIdx + div_length) != -1) {
intIdx = source.indexOf(div, intIdx + div_length);
arynum = intCount;
}
else {
arynum += 2;
break;
}
}
}
else {
arynum = 1;
}
}
else {
arynum = 0;
}
intIdx = 0;
intIdex = 0;
String[] returnStr = new String[arynum];
if (source.compareTo("") != 0) {
if (source.indexOf(div) != -1) {
intIdx = (int) source.indexOf(div);
returnStr[0] = (String) source.substring(0, intIdx);
for (int intCount = 1; ; intCount++) {
if (source.indexOf(div, intIdx + div_length) != -1) {
intIdex = (int) source.indexOf(div, intIdx + div_length);
returnStr[intCount] = (String) source.substring(intIdx + div_length,
intIdex);
intIdx = (int) source.indexOf(div, intIdx + div_length);
}
else {
returnStr[intCount] = (String) source.substring(intIdx + div_length,
source.length());
break;
}
}
}
else {
returnStr[0] = (String) source.substring(0, source.length());
return returnStr;
}
}
else {
return returnStr;
}
return returnStr;
}
public static String dealNull(String str) {
String returnstr = null;
if (str == null) {
returnstr = "";
}
else {
returnstr = str;
}
return returnstr;
}
public static Object dealNull(Object obj) {
Object returnstr = null;
if (obj == null) {
returnstr = (Object) ("");
}
else {
returnstr = obj;
}
return returnstr;
}
static int dealEmpty(String s) {
s = dealNull(s);
if (s.equals("")) {
return 0;
}
return Integer.parseInt(s);
}
public static String replace(String str, String substr, String restr) {
String[] tmp = split(str, substr);
String returnstr = null;
if (tmp.length != 0) {
returnstr = tmp[0];
for (int i = 0; i < tmp.length - 1; i++) {
returnstr = dealNull(returnstr) + restr + tmp[i + 1];
}
}
return dealNull(returnstr);
}
public static String addBr(String txt) {
if (txt != null) {
txt = replace(txt, "\n", "<br>");
//txt = replace(txt,"\n","<BR>");
}
return txt;
}
public static String addColon(String txt) {
if (txt != null) {
//txt = replace(txt,"<br>",":<br>");
//txt = replace(txt,"<BR>",":<BR>");
txt = replace(txt, "<br>", "<br>:");
txt = replace(txt, "<BR>", "<BR>:");
//txt = replace(txt,"<p>",":<p>");
//txt = replace(txt,"<P>",":<P>");
}
return txt;
}
public static String addColonn(String txt) {
if (txt != null) {
txt = replace(txt, "<br>", "<br>:");
txt = replace(txt, "<BR>", "<BR>:");
//txt = replace(txt,"<br>","<br>:");
//txt = replace(txt,"<BR>","<BR>:");
//txt = replace(txt,"<p>",":<p>");
//txt = replace(txt,"<P>",":<P>");
}
return txt;
}
public static String changeColor(String txt) {
if (txt != null) {
txt = replace(txt, "<br>", "</font><br>");
txt = replace(txt, "<br>:", "<br><font color=#408080>:");
}
return txt;
}
public static String delBr(String txt) {
if (txt != null) {
txt = replace(txt, "<br>", "\n");
txt = replace(txt, "<BR>", "\n");
}
return txt;
}
public static String delP(String txt) {
if (txt != null) {
txt = replace(txt, "<P>", "");
txt = replace(txt, "</P>", "<br>");
}
return txt;
}
public static String addSlashes(String txt) {
if (txt != null) {
txt = replace(txt, "\\", "\\\\");
txt = replace(txt, "\'", "\\\'");
}
return txt;
}
public static String unDoAddSlashes(String txt) {
if (txt != null) {
txt = replace(txt, "\\", "");
}
return txt;
}
public static String stripslashes(String txt) {
if (txt != null) {
txt = replace(txt, "\\\\", "\\");
//txt = replace(txt, "\'", "'");
txt = replace(txt, "\\\'", "\'");
txt = replace(txt, "\\\"", "\"");
txt = replace(txt, "\\"", "\"");
//txt = replace(txt, "\'", "'");
}
return txt;
}
public static String htmlEncode(String txt) {
if (txt != null) {
txt = replace(txt, "&", "&");
txt = replace(txt, "&amp;", "&");
txt = replace(txt, "&quot;", """);
txt = replace(txt, "\"", """);
txt = replace(txt, "&lt;", "<");
txt = replace(txt, "<", "<");
txt = replace(txt, "&gt;", ">");
txt = replace(txt, ">", ">");
txt = replace(txt, "&nbsp;", " ");
//txt = replace(txt," "," ");
}
return txt;
}
public static String unHtmlEncode(String txt) {
if (txt != null) {
txt = replace(txt, "&", "&");
txt = replace(txt, """, "\"");
txt = replace(txt, "<", "<");
txt = replace(txt, ">", ">");
txt = replace(txt, " ", " ");
}
return txt;
}
public static String ScriptEncode(String txt) {
if (txt != null) {
txt = replace(txt, "script", "s cript");
txt = replace(txt, "SCRIPT", "s cript");
txt = replace(txt, "Script", "s cript");
txt = replace(txt, "SCript", "s cript");
txt = replace(txt, "<marquee", "<marquee");
txt = replace(txt, "<Marquee", "<marquee");
txt = replace(txt, "<MARQUEE", "<marquee");
txt = replace(txt, "<html", "<html");
txt = replace(txt, "<Html", "<html");
txt = replace(txt, "<HTML", "<HTML");
txt = replace(txt, "<head", "<head");
txt = replace(txt, "<HEAD", "<HEAD");
txt = replace(txt, "<Head", "<head");
txt = replace(txt, "<title", "<title");
txt = replace(txt, "<TITLE", "<TITLE");
txt = replace(txt, "<Title", "<title");
txt = replace(txt, "<body", "<body");
txt = replace(txt, "<BODY", "<BODY");
txt = replace(txt, "<Body", "<body");
txt = replace(txt, "<frame", "<frame");
txt = replace(txt, "<FRAME", "<FRAME");
txt = replace(txt, "<Frame", "<frame");
txt = replace(txt, "<frameset", "<frameset");
txt = replace(txt, "<FRAMESET", "<FRAMESET");
txt = replace(txt, "<Frameset", "<frameset");
txt = replace(txt, "<meta", "<meta");
txt = replace(txt, "<META", "<META");
txt = replace(txt, "<Meta", "<Meta");
/*
txt = txt.toUpperCase(Sys.getLocale());
txt = replace(txt, "SCRIPT", "S CRIPT");
txt = replace(txt, "<MARQUEE", "<marquee");
txt = replace(txt, "<HTML", "<HTML");
txt = replace(txt, "<HEAD", "<HEAD");
txt = replace(txt, "<TITLE", "<TITLE");
txt = replace(txt, "<BODY", "<BODY");
txt = replace(txt, "<FRAME", "<FRAME");
txt = replace(txt, "<FRAMESET", "<FRAMESET");
txt = replace(txt.toLowerCase(Sys.getLocale()), "script", "s cript");
txt = replace(txt.toLowerCase(Sys.getLocale()), "<marquee", "< marquee");
txt = replace(txt.toLowerCase(Sys.getLocale()), "<html", "< html");
txt = replace(txt.toLowerCase(Sys.getLocale()), "<head", "< head");
txt = replace(txt.toLowerCase(Sys.getLocale()), "<title", "< title");
txt = replace(txt.toLowerCase(Sys.getLocale()), "<body", "< body");
txt = replace(txt.toLowerCase(Sys.getLocale()), "<frame", "< frame");
txt = replace(txt.toLowerCase(Sys.getLocale()), "<frameset", "< frameset");
*/
}
return txt;
}
public static boolean isNumber(String validString) {
byte[] tempbyte = validString.getBytes();
for (int i = 0; i < validString.length(); i++) {
//by=tempbyte[i];
if ( (tempbyte[i] < 48) || (tempbyte[i] > 57)) {
return false;
}
}
return true;
}
public static boolean isChar(String validString) {
byte[] tempbyte = validString.getBytes();
for (int i = 0; i < validString.length(); i++) {
// by=tempbyte[i];
if ( (tempbyte[i] < 48) || ( (tempbyte[i] > 57) & (tempbyte[i] < 65)) ||
(tempbyte[i] > 122) || ( (tempbyte[i] > 90) & (tempbyte[i] < 95)) ||
( (tempbyte[i] > 95) & (tempbyte[i] < 97))) {
return false;
}
}
return true;
}
public static boolean isLetter(String validString) {
byte[] tempbyte = validString.getBytes();
for (int i = 0; i < validString.length(); i++) {
//by=tempbyte[i];
if ( (tempbyte[i] < 65) || (tempbyte[i] > 122) ||
( (tempbyte[i] > 90) & (tempbyte[i] < 97))) {
return false;
}
}
return true;
}
public static String iso2gb(String str) {
if (str != null) {
byte[] tmpbyte = null;
try {
tmpbyte = str.getBytes("ISO8859_1");
}
catch (Exception e) {
System.out.println("Error: Method: dbconn.iso2gb :" + e.getMessage());
}
try {
str = new String(tmpbyte, "GBK");
}
catch (Exception e) {
System.out.println("Error: Method: dbconn.gb2iso :" + e.getMessage());
}
}
return str;
}
public static String gb2iso(String str) {
if (str != null) {
byte[] tmpbyte = null;
try {
tmpbyte = str.getBytes("GBK");
}
catch (Exception e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -