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

📄 unicoder.java

📁 《jsp网站开发技术》中的源代码(清华大学出版社)
💻 JAVA
字号:
//Unicoder.java
package com.javacat.util;
/**
*This class can help you revent a string to unicode
*or parse unicode to string
*/
public class Unicoder
{
	//source string
	String source;
	//constuctors
	public Unicoder()
	{}
	public Unicoder(String str)
	{
		setSource(str);
	}
	/**
	*set the source string
	*@param str the source string to be set
	*/
	public void setSource(String str)
	{
		source=str;
	}
	/**
	*get the source string
	*/
	public String getSource()
	{
		return source;
	}
	/**
	*parse character to Unicode
	*@param ch the character to be revent
	*@return the Unicode string
	*/
	public static String charToUnicode(char ch)
	{
		String code = "\\u"+Integer.toHexString((int)ch);
   		return code;
	}
	/**
	*revent a string to unicode
	*@param the string to be revented
	*@return the unicode string
	*/
	public static String StringToUnicode(String src)
	{
		StringBuffer dest=new StringBuffer();
		if(src!=null){
			int Len=src.length();
			char[] cdest=new char[Len];
    			src.getChars(0,Len,cdest,0);
			for(int i=0;i<Len;i++)    
			{
      				dest.append(charToUnicode(cdest[i]));
			}
		}
		return dest.toString();
	}
	/**
	*parse unicode(in int type) to char
	*/
	public static char intToChar(int codno)
	{
		return (char)codno;
	}
	/**
	*parse
	*@return the source string's unicode
	*/
	public String getUnicode()
	{
		if(getSource()!=null)
		 return StringToUnicode(getSource());
		else return "0";
	}
}

⌨️ 快捷键说明

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