- //**************************************************************************
- //UnicodetoChar
- public class UnicodetoChar { //以空格为分隔
- private String theString;
- public UnicodetoChar(String theString){
- this.theString = theString;
- }
- public String convert(){
- int i=0; //临时变量
- String s = new String (); //用于保存转换后的字符
- String thechar = new String();//当前将要转换的Unicode
- while(i<theString.length()){ //每次循环转换一个Unicode码
- while(i<theString.length()&&(theString.charAt(i)!=' ')){
- thechar += theString.charAt(i++); //其实每次的thechar是单个字符
- }
- s+=(char)Integer.parseInt(thechar);
- thechar ="";
- i++;
- }
- return s;
- }
- }
- //**************************************************************************
- //ChartoUnicode
- public class ChartoUnicode {
- private String theString;
- public ChartoUnicode(String aString){
- theString = aString;
- }
- public String convert(){
- int i,j;
- String chartodigit = new String();// 保存转换后的Unicode码
- for(i=0;i<theString.length();i++){ //每次循环转换一个字符
- j = (int)theString.charAt(i); //将一个字符转换为Unicode码
- chartodigit+=j+" "; //将转换后的Unicode码保存起来
- }
- return chartodigit;
- }
- }
Unicode码和字符间的相互转换
最新推荐文章于 2024-08-06 14:35:35 发布