⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringutil.java

📁 基本分数查询功能,自己的毕业设计作品!希望能给大家一点帮助!
💻 JAVA
字号:
package org.xk.util;
/**
 * Description: 
 * @author xk
 * 
 * @version 1.0, 2007-10-16
 */
import java.io.UnsupportedEncodingException;

public class StringUtil {
	 
	/**
	 * 将字符串转成uncode码	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static String setUtf8Url(String str) throws Exception{
		String s="";
		if(str!=null&&!str.equals("")){
			s=java.net.URLEncoder.encode(str,"utf-8");
		}
		return s;
	}
	
	/**
	 *  将字符串转换成GBK编码
	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static String convertStrToGBK(String s) {
	    try {
		    return new String(s.getBytes("iso-8859-1"),"GBK");
		} catch (Exception e) {
            return null;
        }
	}
	
	/**
	 * 将字符串转换成ISO编码
	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static String convertStrToISO(String s)
	{
		try {
			return new String(s.getBytes("GBK"),"iso-8859-1");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return null;
		}
		
	}
	
	
	/**
	 *  将字符串转换成utf-8编码
	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static String toUtf8Code(String input) {
		try {
			if (null != input && input.indexOf("null")<0) {
				byte[] bytes = input.getBytes("ISO8859_1");
				input = new String(bytes,"utf-8");
			}
			else{
				input = "";
			}

		}
		catch (Exception e) {
			e.printStackTrace();
		}

		return input;
	}
	
	/**
	 *判断对象是否为空,如果为空,返回“”; 如果不为空,返回对象的toString()
	 * @param o    被判断的对象
	 * @return	
	 */
	public static String removeNull(Object o) {	
		
		return removeNull(o, "");
	}

	public static String removeNullInHtml(Object o) {
		if (o == null || o.toString().trim().equals("")) {
			return "&nbsp;";
		}
		
		return o.toString().trim();
	}
		
	/**
	 * 判断对象是否为空,如果为空,返回字符串s; 如果不为空,返回对象的toString()
	 * @param o 	被判断的对象
	 * @param s		默认值
	 * @return	
	 */
	public static String removeNull(Object o, String s) {
		if (o == null) {
			return s;
		}
		
		return o.toString().trim();
	}

	/**
	 * 消除字符串中的html代码
	 * @param str
	 * @return
	 */
	public static   String   htmcode(Object  str)  
	  {  
	        String  code=str!=null?str.toString():"";  
	        try  
	        {        
	                while(code.indexOf("<")!=-1&&code.indexOf(">")!=-1)  
	                {  
	                StringBuffer   sb=new   StringBuffer(code);  
	                code=sb.replace(code.indexOf("<"),code.indexOf(">")+1,"").toString();  
	                //code=sb.replace(code.indexOf(">"),code.indexOf(">")+1,"").toString();  
	                }  
	                return   code;  
	        }catch(Exception   e){System.out.print("htmcode.err");return   code;}  
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -