?? stringutil.java
字號(hào):
/*
* Created on 2006-3-17
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package cn.com.aheadsoft.common;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @author
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class StringUtil {
/**
* 設(shè)置有效的顯示天數(shù)
* @param _date 格式:YY-MM-DD 與
* @param num 顯示天數(shù)
* @return
*/
public static boolean CheckDateNum(String _date,int num){
try{
SimpleDateFormat old_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date old_date = old_dateFormat.parse(_date);
Calendar oldCal =Calendar.getInstance();
oldCal.setTime(old_date);
//以格林威治標(biāo)準(zhǔn)時(shí)間 1970 年 1 月 1 日作為參考數(shù)比較
Long oldDateNum =oldCal.getTimeInMillis()/(60*60*1000*24);
// System.out.println(" old date num="+oldCal.getTimeInMillis()/(60*60*1000*24));
Calendar newCal =Calendar.getInstance();
newCal.setTime(new Date());
//System.out.println("new =="+newCal.getTimeInMillis());
Long newDateNum =newCal.getTimeInMillis()/(60*60*1000*24);
// System.out.println(newDateNum+" - "+oldDateNum);
if((newDateNum - oldDateNum) <= num){
return true;
}
}catch(Exception e){
e.printStackTrace();
}
return false;
}
/**
* 從8859_1轉(zhuǎn)向GB2312
* @param oldString
* @return
*/
public static String I8859_1ToGB2312(String oldString) {
try {
oldString = oldString.trim();
return new String(oldString.getBytes("8859_1"), "GB2312");
} catch (Exception e) {
return oldString;
}
}
/**
* 從GB2312轉(zhuǎn)向8859_1
* @param oldString
* @return
*/
public static String IGB2312To8859_1(String oldString) {
try {
oldString = oldString.trim();
return new String(oldString.getBytes("GB2312"), "8859_1");
} catch (Exception e) {
return oldString;
}
}
/**
* Escape SQL tags,將 ' 轉(zhuǎn)化為 ''; \ 轉(zhuǎn)化為 \\.
* @param input string to replace
* @return string
*/
public static String escapeSQLTags(String input) {
if (input == null || input.length() == 0)
return input;
StringBuffer buf = new StringBuffer();
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '\\')
buf.append("\\\\");
else if (ch == '\'')
buf.append("\'\'");
else
buf.append(ch);
}
return buf.toString();
}
public static String getRealFileName(String fileName) {
if (fileName.indexOf('/') > 0)
fileName = fileName.substring(fileName.lastIndexOf('/') + 1,
fileName.length());
if (fileName.indexOf('\\') > 0)
fileName = fileName.substring(fileName.lastIndexOf('\\') + 1,
fileName.length());
return fileName;
}
public static String changeFilePath(String path){
if(path.length() >0){
path=path.replaceAll("\\\\","/");
}else
return path;
return path;
}
/**
* Escape HTML 特殊字符轉(zhuǎn)換.
*
* @param input
* string to replace
* @return string
*/
public static String escapeHTMLTags(String input) {
if (input == null || input.length() == 0)
return input;
StringBuffer buf = new StringBuffer();
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '<')
buf.append("<");
else if (ch == '>')
buf.append(">");
else if (ch == '&')
buf.append("&");
else if (ch == '"')
buf.append(""");
else
buf.append(ch);
}
return buf.toString();
}
/**
* 頁(yè)面內(nèi)容轉(zhuǎn)化文本內(nèi)容
* Convert <BR/> to "\r\n"
* " " to " "
* @param input
* string to convert
* @return string
*/
public static String HtmlToConvert(String input) {
input = replace(input, "<BR>", "\n");
input = replace(input, " ", " ");
return input;
}
/**
* 文本內(nèi)容轉(zhuǎn)化頁(yè)面內(nèi)容
* '\n' to '<br>'
* " " to " "
* @param input
* string to convert
* @return string
*/
public static String convertToHtml(String input) {
input = replace(input, "\n", "<BR>");
input = replace(input," "," ");
return input;
}
public static String changeDateForm(String dataChar){
String newString =dataChar.substring(0,10);
return newString;
}
/**
* 替換,mainString中所有的oldString換成newString
*
* @param mainString
* @param oldString
* @param newString
* @return
*/
public static String replace(String mainString, String oldString,
String newString) {
if (mainString == null)
return null;
int i = mainString.lastIndexOf(oldString);
if (i < 0)
return mainString;
StringBuffer mainSb = new StringBuffer(mainString);
while (i >= 0) {
mainSb.replace(i, i + oldString.length(), newString);
i = mainString.lastIndexOf(oldString, i - 1);
}
return mainSb.toString();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -