==============================================================================
上篇写了一篇文章,说中文解决方法的,这一篇在做一个小的整理,
与我联系:[email protected] QQ: 9690501
最新修改时间 : 2003-11-24
==============================================================================
将以前的文章,以及中文问题整理成为一个类,方便大家可以调用
/*函数:public String gb(String str) *功能:将字符串以gb2312输出,解决中文字体乱码
*/ import java.io.UnsupportedEncodingException;
public class gb2312 {
public gb2312() { }
//---------输出中文------------------------------------------- public String gb2312(String str) { String s1 = null; if(str == null) s1 = null; else try { /** *将字符串str进行转换,并且将其最终值赋予s1 */
byte[] tmpbyte=str.getBytes("ISO8859_1"); s1=new String(tmpbyte); } catch(UnsupportedEncodingException unsupportedencodingexception) { } return s1; }
//-------------中文内码----------------------------------------------- public String toChinese(String strvalue) { try{ if(strvalue==null) return null; else { strvalue = new String(strvalue.getBytes("gb2312"), "GBK"); return strvalue; } }catch(Exception e){ return null; } } //-----------输出中文 public static String databasetoChinese(String strvalue) { try{ if(strvalue==null) return null; else { strvalue = new String(strvalue.getBytes("ISO-8859-1"),"gb2312"); return strvalue; } }catch(Exception e){ return null; } } }
阅读者如果调用其中一个函数不能完成转码,可以尝试gb2312,toChinese 等的转换-)
==============================================================================
与我联系:[email protected] QQ: 9690501 网名: 伊-阿尔法 (E.alpha)
最新修改时间 : 2003-11-24
============================================================================== 
|