www.pudn.com > Hotel.rar > Codechange.java


/* 
 * Created on 2007-6-17 
 * 
 * TODO To change the template for this generated file go to 
 * Window - Preferences - Java - Code Style - Code Templates 
 */ 
package codechange; 
 
/** 
 * @author yongyong 
 * 
 * TODO To change the template for this generated type comment go to 
 * Window - Preferences - Java - Code Style - Code Templates 
 */ 
public class Codechange { 
	 public Codechange() { 
	    } 
	public static void main(String[] args) { 
	} 
	public static String toUnicode(String str){ 
   	 try{ 
    		if(str==null) 
    		  str=""; 
    		else 
    		  str=new String(str.getBytes("GB2312"),"ISO-8859-1"); 
    	}catch(Exception e){System.out.println("In DealString toGB");e.printStackTrace();} 
        return str; 
    } 
    public static String toGB(String str){ 
   	try{ 
   		if(str==null) 
   		  str=""; 
   		else 
   		  str=new String(str.getBytes("ISO-8859-1"),"GB2312"); 
   	}catch(Exception e){System.out.println("In DealString toGB");e.printStackTrace();} 
       return str; 
    } 
    public static String replace(String source,String oldstr,String newstr){ 
   	 StringBuffer output=new StringBuffer(); 
   	 int lengthofSource=source.length(); 
   	 int lengthofOldstr=oldstr.length(); 
   	 int posStart=0; 
   	 int pos; 
   	 while((pos=source.indexOf(oldstr,posStart))>=0){ 
   		 output.append(source.substring(posStart,pos)); 
   	     output.append(newstr); 
   	     posStart=pos+lengthofOldstr; 
   	 } 
   	 if(posStart