?? str.java
字號:
} else if (fileExtName.equals("png")) {
return true;
} else if (fileExtName.equals("JPG")) {
return true;
} else if (fileExtName.equals("JPEG")) {
return true;
} else if (fileExtName.equals("GIF")) {
return true;
} else if (fileExtName.equals("BMP")) {
return true;
} else if (fileExtName.equals("PNG")) {
return true;
} else {
return false;
}
}
/**
* cover 0 with the blank postion
*
* @param str
* the string use to change
* @param length
* the length your want to cover
* @param c
* the covered char,like '0' or ' ';
* @param fix
* prefix or suffix;
* @return the covered string
*/
public static String coverLength(String str, int length, char c, String fix) {
if (isNull(str)) {
return "";
}
String rt = "";
int strLength = str.length();
length = length > strLength ? length : strLength;
for (int i = 0; i < length - strLength; i++) {
rt += c;
}
if (fix.equals("prefix")) {
rt += str;
} else {
rt = str + rt;
}
return rt;
}
public static String coverLength(String str, int length) {
return coverLength(str, length, '0', "prefix");
}
public static String coverLength(String str, int length, char c) {
return coverLength(str, length, c, "prefix");
}
/**
* 取字符串的前length位。如果flag為1則超過length位則顯示... 默認不顯示。
*/
public static String getSub(String str, int length, int flag) {
if (Str.isNull(str)) {
return "";
}
int len = str.length();
String temp = str.substring(0, len > length ? length : len);
if ((flag == 1) && (len > length)) {
temp += "...";
}
return temp;
}
public static String getSub(String str, int length) {
return getSub(str, length, 0);
}
public static String getSub(String str) {
return getSub(str, 10, 0);
}
/**
* 比Integer里的方法好處是不會出現str為空的exception
*/
public static float parseFloat(String str) {
if (isNull(str)) {
return 0.0f;
} else {
return Float.parseFloat(str);
}
}
public static int parseInt(String str) {
if (isNull(str)) {
return 0;
} else {
return Integer.parseInt(str);
}
}
/**
* 判斷日期是否過期,若過期則顯示為紅色字體,并顯示"過期"兩字
*/
public static String compareToToday(String date) {
if (Str.isNull(date)) {
return "";
}
String currentTime = TimeUtil.getYMD();
if (date.compareTo(currentTime) < 0) {
return "<span class=\"error\"> " + getSub(date) + " 過期</span>";
} else {
return getSub(date);
}
}
/**
* 全角數字到半角數字的轉換
*
*
* if c = '1' THEN SW[I] := '1'; if c = '2' THEN SW[I] := '2'; if c = '3'
* THEN SW[I] := '3'; if c = '4' THEN SW[I] := '4'; if c = '5' THEN SW[I] :=
* '5'; if c = '6' THEN SW[I] := '6'; if c = '7' THEN SW[I] := '7'; if c =
* '8' THEN SW[I] := '8'; if c = '9' THEN SW[I] := '9'; if c = '0' THEN
* SW[I] := '0'; if c = '.' THEN SW[I] := '.';
*/
/**
* 全角到半角的轉換. 全角字符的第二個字節是從-93開始的。全角空格-95-95
*/
public static String qj2bj(String str) throws Exception {
if (isNull(str)) {
return "";
}
String temp = "";
byte[] bs = str.getBytes();
System.out.println("" + bs[0] + " " + bs[1]);
if (bs.length == 1) {
temp = str;
} else if (bs[1] == (byte) 163) {
temp = (char) (bs[1] + 128) + "";
System.out.println((char) (49));
}
return temp;
/*
* String dst = src; dst = replaceAll(dst, ")", ")"); dst =
* replaceAll(dst, "(", "("); dst = replaceAll(dst, "--", "--"); dst =
* replaceAll(dst, "O", "o"); dst = replaceAll(dst, " ", " "); dst =
* replaceAll(dst, "‐", "-"); dst = replaceAll(dst, "—", "-"); dst =
* replaceAll(dst, "―", "-"); dst = replaceAll(dst, "、", ","); dst =
* replaceAll(dst, "。", "。"); dst = replaceAll(dst, "〈", " <"); dst =
* replaceAll(dst, "〉", ">");
*
* return dst;
*/
}
/**
* 將用戶輸入的換行,空格格式不好的文本,換成 每段兩個空行,每段前空兩個字符。
*/
public static String doNr(String src) throws Exception {
src = replaceAll(src, "'", "‘");
src = quanJiao2BanJiao(src);
//Pattern p=Pattern.compile("^ * *");
Pattern p = Pattern.compile("^ *");
Matcher m = p.matcher(src);
String temp = m.replaceAll(" ");
p = Pattern.compile("[\r\n]+ +");
//p=Pattern.compile("[\r\n]+ + *");
m = p.matcher(temp);
temp = m.replaceAll("\r\n");
p = Pattern.compile("[\r\n]+ *");
m = p.matcher(temp);
temp = m.replaceAll("\r\n\r\n ");
p = Pattern.compile(" ");
m = p.matcher(temp);
temp = m.replaceAll("");
/*
* p=Pattern.compile("[\r\n]+ *"); m=p.matcher(temp);
* temp=m.replaceAll("");
*
* p=Pattern.compile("@@+ *"); m=p.matcher(temp); temp=m.replaceAll("");
*/
// p=Pattern.compile("^\r\n+");
// m=p.matcher(temp);
// temp=m.replaceAll("\r\n");
return temp;
}
/**
* 全角到半角的轉換. <br>
*/
public static String quanJiao2BanJiao(String src) throws Exception {
if (src == null || src.equals("")) {
return "";
}
String dst = src;
dst = replaceAll(dst, ")", ")");
dst = replaceAll(dst, "(", "(");
dst = replaceAll(dst, "--", "--");
dst = replaceAll(dst, "O", "o");
dst = replaceAll(dst, " ", " ");
//dst = replaceAll(dst, "“", "“");
//dst = replaceAll(dst, "‘", "\''");
dst = replaceAll(dst, "‐", "-");
dst = replaceAll(dst, "—", "-");
dst = replaceAll(dst, "―", "-");
//dst = replaceAll(dst, "’", "\''");
//dst = replaceAll(dst, "”", "\''");
dst = replaceAll(dst, "、", ",");
dst = replaceAll(dst, "。", "。");
dst = replaceAll(dst, "〈", "<");
dst = replaceAll(dst, "〉", ">");
// dst = replaceAll(dst, "《", "");
//dst = replaceAll(dst, "〈", "<");
return dst;
}
/**
* 取文件的大小,根據他們的大小用相應的MB,KB,Byte為單位。
*/
public static String getFileSizePrint(int fileSize) {
String temp;
if (fileSize >= 1024 * 1024) {
temp = fileSize / 1024 / 1024 + " MB";
} else if (fileSize >= 1024) {
temp = fileSize / 1024 + " KB";
} else {
temp = fileSize + " Byte";
}
return temp;
}
public static String copyRight() {
return "<!--author: 彭法鑾 Email: pengfaluan@tom.com QQ: 8330108 --!>";
}
/*
* String fbnr = ""; //String fbnr1=""; //String fbnr2=""; // String fbt=""; //
* String fbt1=""; // String fbt2=""; // String bz=""; //String bz1=""; //
* String bz2="";
*
* java.util.ArrayList yprys = FbzbCtrl.findBy(" fbdx=0");
*
* if (yprys != null) {
*
* for (int i = 0; i < yprys.size(); i++) {
*
* Fbzb fbzb = (Fbzb) yprys.get(i);
*
* fbnr = fbzb.getFbnr(); //System.out.println("fbnr chishi"+fbnr); fbnr =
* Str.replaceAll(fbnr, " ", " "); fbnr = Str.replaceAll(fbnr, " ", "
* "); fbnr = Str.replaceAll(fbnr, " <br> ", "\n"); //
* fbnr=Str.replaceAll(fbnr,"\n",""); // System.out.println("fbnr2
* 2"+fbnr2);
*
* /*fbt=fbzb.getFbt(); fbt1=Str.replaceAll(fbt," "," ");
* fbt2=Str.replaceAll(fbt1," <br> ","\n");
*
* System.out.println("fbt chishi"+fbt); System.out.println("fbt 22"+fbt2);
*
* bz=fbzb.getBz(); bz1=Str.replaceAll(bz," "," ");
* bz2=Str.replaceAll(bz1," <br> ","\n");
*
* fbzb.setFbnr(fbnr); //fbzb.setFbt(fbt2); //fbzb.setBz(bz2);
*
* if (FbzbCtrl.update(fbzb) == 1) { System.out.println("update OK !"); } } } }
*
*
* 將輸入的String的%換成*號輸出 public static String changePercent2Star(String str) {
* return str.replace('%', '*'); }
*
* 將輸入的String的*換成%號輸出
*
* public static String changeStar2Percent(String str) { return
* str.replace('*', '%'); }
*
*
* public static String deleteDanYinHao(String str) { if (str == null)
* return null; return str.replace('\'', '"'); } /** 將str中的"'"改成"''",以適應sql
* string語句
*
*
* public static String doSqlString(String sStr) {
*
* if (sStr == null || sStr.equals("")) { return sStr; }
*
* StringBuffer sTmp = new StringBuffer(); int i = 0; while (i <=
* sStr.length() - 1) { if (sStr.charAt(i) == '\'') { sTmp =
* sTmp.append("''"); } else { sTmp = sTmp.append(sStr.substring(i, i + 1)); }
* i++; } String S1; S1 = sTmp.toString(); return S1; }
*
*
* /** 將null或空換成HTML能顯示的格式
*
* public static String doNullHTML(String str) { if (str == null ||
* str.trim().equals("")) str = " "; return str; }
*
* public static String doWithQuote(String sStr) { if (sStr == null ||
* sStr.equals("")) { return sStr; } StringBuffer sTmp1 = new
* StringBuffer(); int i = 0; while (i <= sStr.length() - 1) { if
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -