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

📄 stringutil.java

📁 新闻系统  此系统是用struts+spring+hibernate开发的 开发环境:eclipse3.1+MyEclipse4.1+tomcat 5.0+oracle 8.1 整个系统实现
💻 JAVA
字号:
package com.news.page;


import java.util.regex.Matcher;
import java.util.regex.Pattern;



/**
 * String Utility Class This is used to encode passwords programmatically
 * 
 * <p>
 * <a h ref="StringUtil.java.html"> <i>View Source </i> </a>
 * </p>
 * 
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible </a>
 */
public class StringUtil {

	/**
	 * @param english
	 * @return
	 */
	public static final boolean isEnglish(String english) {
		Pattern p = null;
		Matcher m = null;
		boolean b;
		String s = null;
		p = Pattern.compile("\\w*\\s*\\w*");
		m = p.matcher(english);
		b = m.matches();
		return b;
	}


	  /**
	   * Replaces all occurances of oldString in mainString with newString
	   * @param mainString The original string
	   * @param oldString The string to replace
	   * @param newString The string to insert in place of the old
	   * @return mainString with all occurances of oldString replaced by newString
	   */
	  public static String replaceString(String mainString, String oldString,
	                                     String newString) {
	    if (mainString == null) {
	      return null;
	    }
	    if (oldString == null || oldString.length() == 0) {
	      return mainString;
	    }
	    if (newString == null) {
	      newString = "";
	    }

	    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();
	  }


	  /**
	   * 过滤空字符串
	   */
	  public static String getString(String strOld) {
	    if (strOld == null || strOld.equalsIgnoreCase("null") || strOld.equalsIgnoreCase("'null'")) {
	      strOld = "";
	      return "";
	    } else {
	      return strOld;
	    }
	  }
	  
	  /**
	   * 转换web应用中的unicode码为中文字符
	   * @param strIn String
	   * @return String
	   */
	  public static String unicodeToGB(String strIn) {
	    String strOut = null;
	    if (strIn == null || (strIn.trim()).equals(""))return strIn;
	    try {
	      byte[] b = strIn.getBytes("ISO8859_1");
	      strOut = new String(b, "GBK");
	    } catch (Exception e) {
	      throw new RuntimeException(e);
	    }
	    return strOut;
	  }
}

⌨️ 快捷键说明

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