📄 util.java
字号:
package jinLing.pub;
import java.util.*;
public class Util {
public Util() {
}
/**
* 功能:null转化为string
*/
public static String getNulltoStr(Object o) {
String str = "";
if (o != null)
str = (String) o;
return str;
}
/**
* 功能:判断是否不为空
*/
public static boolean bIsEmpty(String str) {
boolean bisNull = false;
if (str == null || str == "" || str.trim().equals(""))
bisNull = true;
return bisNull;
}
/**
* 功能:返回一个子符串
*/
public static String Copy(String source, int beginIndex, int Count) {
if (source.length() < Count)
Count = source.length();
if (beginIndex < 0)
beginIndex = 0;
return source.substring(beginIndex, Count);
}
/**
* 功能:返回一个子符串
*/
public static String Copy(Object source, int beginIndex, int Count) {
String str = getNulltoStr(source);
return Copy(str, beginIndex, Count);
}
/**
* 功能:字符串转换成整型
*/
public static long StrToLon(Object o) {
String str = getNulltoStr(o);
if (str == null || str == "" || str.trim().equals(""))
str = "0";
if(str.indexOf(".")!=-1)
str = str.substring(0,str.indexOf(".")).trim();
if (str == "" || str.trim().equals(""))
str = "0";
return Integer.parseInt(str.trim());
}
/**
* 功能:字符串转换成整型,并去掉小数点后的位数
*/
public static int StrToInt(String str) {
if (str == null || str == "" || str.trim().equals(""))
str = "0";
if(str.indexOf(".")!=-1)
str = str.substring(0,str.indexOf(".")).trim();
if (str == "" || str.trim().equals(""))
str = "0";
return Integer.parseInt(str.trim());
}
/**
* 功能:去掉小数后面多余的0
*/
public static String trimFloat(String str) {
if (str == null || str == "" || str.trim().equals(""))
str = "0";
if(str.endsWith("0"))
str = str.substring(0,str.length()-1);
if(str.endsWith("0"))
str = str.substring(0,str.length()-1);
if(str.endsWith("."))
str = str.substring(0,str.length()-1);
if (str == "" || str.trim().equals(""))
str = "0";
return str;
}
/**
* 功能:Object 转换成整型
*/
public static int StrToInt(Object o) {
String str = getNulltoStr(o);
return StrToInt(str);
}
/**
* 功能:Object 转换成浮点型
*/
public static double StrToFlo(Object o) {
String str = getNulltoStr(o);
if (str == null || str == "" || str.trim().equals(""))
str = "0";
double flo = Float.parseFloat(str);
//String.valueOf(flo);
return flo;
}
/**
* 功能:打印调试信息
*/
public static void debug(Object obj) {
//write(String.valueOf(obj));
System.out.println(obj);
}
/**
* 功能:转换成中文字符
*/
public static String toGb(String uniStr) {
String gbStr = "";
if (uniStr == null) {
uniStr = "";
}
try {
byte[] tempByte = uniStr.getBytes("ISO8859_1");
gbStr = new String(tempByte, "GBK");
}
catch (Exception ex) {
System.out.print(ex);
}
return gbStr;
}
public static String toUni(String gbStr){
String uniStr = "";
if(gbStr == null){
gbStr = "";
}
try{
byte[] tempByte = gbStr.getBytes("GBK");
uniStr = new String(tempByte,"ISO8859_1");
}catch(Exception ex){
System.out.print(ex);
}
return uniStr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -