\u4e2d\u56fd\ java代码里怎么转换成中文呢?

解决方案 »

  1.   

    String str = new String("\u4e2d\u56fd");
    System.out.println(str);
      

  2.   

    楼主的意思是把 \u4e2d\u56fd\ java  的Unicode码转化?
      

  3.   

    这个可以实现:
    Java codeString str = new String("\u4e2d\u56fd");
        System.out.println(str);
      

  4.   

    String str = "\u4e2d\u56fd";System.out.println(str);
      

  5.   


    String s = "\\u4e2d\\u56fd";
    StringBuffer sb = new StringBuffer();
    Pattern p = Pattern.compile("(?i)\\\\u([\\da-f]{4})");
            Matcher m = p.matcher(s);
            while(m.find()) {
             m.appendReplacement(sb, Character.toString((char)Integer.parseInt(m.group(1), 16)));
            }
            m.appendTail(sb);
    System.out.println(sb.toString());
      

  6.   

    这样可以实现,但"\u4e2d\u56fd"是放在一个String变量里面的,而我用
    String a=new String(a);a就不是中文了???
      

  7.   

    装一个eclipse插件 http://www.lifeispig.cn/article.asp?id=116 看一下这个插件吧..还好用.我一直是用他做国际化..
      

  8.   


    没有问题啊,怎么可能不行呢?那还真邪门了呵呵public static void main(String args[]){
    String str1 = "\u4e2d\u56fd";
    String str2 = new String("\u4e2d\u56fd");

    System.out.print(str1 +","+ str2);
    }
    中国,中国
      

  9.   


    // 这样子是实现了吗?
    String str = new String("\u4e2d\u56fd");
    System.out.println(str);// 要这样子的话
    // 下面这样子都会出来"中国", 根本连 new String 都不用
    String str = "\u4e2d\u56fd"; 
    System.out.println(str);\uxxxx 刚好也是 java 定义字符串内容时的一种转义形式
      

  10.   

    任意编码转换
    ByteBuffer bbuf = ByteBuffer.wrap("\u4e2d\u56fd".getBytes("utf-16"));

    Charset cs = Charset.forName("utf-16");
    CharsetDecoder decoder = cs.newDecoder();
    CharBuffer cbuf = decoder.decode(bbuf);


    cs = Charset.forName("gbk");
    CharsetEncoder encoder = cs.newEncoder();
    ByteBuffer outbuffer = encoder.encode(cbuf);
    String str1 = new String(outbuffer.array(), "gbk");
    System.out.println(str1);
      

  11.   

    赫赫,那你就用最傻的办法:  String content = new String("\u4e2d\u56fd".getBytes("gbk"),"gbk");
     System.out.println(content);
    楼上的都说了
    String str = new String("\u4e2d\u56fd"); 
    System.out.println(str); 
    也行,因为中文操作系统 JVM的默认编码格式就是GBK.
    如果你是英文操作系统,就按我上面那样写全了。
      

  12.   

    你那两行代码都是可以的但我这边很怪String str的变量的值打印出来是  \u4e2d\u56fd但想把它转换成中文的“中国”详细如下:
    有一个client.properties里写有
    name=中国然后
    public static Hashtable properties=null;
    StringUtil st=new StringUtil();
    properties=st.loadProperties("/client.properties",'=');String  str1=(String)properties.get("name");打印的str1却是"\u4e2d\u56fd",而不是"中国"************String str2 = "\u4e2d\u56fd";
    String str3 = new String(str2); 
    System.out.println("======str3========"+str3);
    这样又可以
      

  13.   

    用这个:    String str1=(String)properties.get("name");     StringBuffer sb = new StringBuffer();
        Pattern p = Pattern.compile("(?i)\\\\u([\\da-f]{4})");
        Matcher m = p.matcher(str1);
        while(m.find()) {
            m.appendReplacement(sb, Character.toString((char)Integer.parseInt(m.group(1), 16)));
        }
        m.appendTail(sb);    str1 = sb.toString();
      

  14.   

    我用的是jdk 1.3,并不支持jdk 6.0的APT
    Pattern 
    Matcher 
      

  15.   

    1.3 有不熟了看这个能不能用   String str1=(String)properties.get("name");
       StringBuffer sb = new StringBuffer(str1);
        
       int pos;
       while ((pos=sb.indexOf("\\u"))>-1) {
          String tmp = sb.substring(pos, pos+6);
          sb.replace(pos, pos+6, Character.toString((char)Integer.parseInt(tmp.substring(2), 16)));
       }
    str1 = sb.toString();
       System.out.println(str1);
      

  16.   

    一般在ECLIPSE导入插件就行了。
      

  17.   

    对,在Eclipse中从网上下一个插件,就是在Application.properts文件中
    就可以把汉字变成编码。。然后就读取该文件 就可了
      还有就是在Jbuidel中也可以将汉字转换成编码
      

  18.   

    换一种思路,怎么把以下的第二行代码变成String str3 = new String("\u4e2d\u56fd"); 可以用java中的转义字符String str3 = new String("\(这里应该怎么写呢?)str2"); 
    String str2 = "\u4e2d\u56fd"; 
    String str3 = new String(str2); 
    System.out.println("======str3========"+str3); 
      

  19.   

    答:一点都不奇怪.楼主忽略了:你是从属性文件中读取\u4e2d\u56fd的.当你读入String str1中时,str1实际上放的是:\\u4e2d\\u56fd,这就是你看到的结果.
    由于你的JDK1.3 ,我就用JDK1.0来写一个转换方法如下(保证楼主成功):public static String convert(String s) 
        {
                  StringBuffer sb = new StringBuffer();
                  int i=-1;
                  int pos=0;
                  while((i=s.indexOf("\\u",pos))!=-1)
                  {
                      sb.append(s.substring(pos,i));
                      if(i+5<s.length())
                      { 
                          pos=i+6;
                          sb.append((char)Integer.parseInt(s.substring(i+2,i+6),16));
                      }//if
                  }//while
                  sb.append(s.substring(pos));
                 
                 return sb.toString();
        }
    若你的属性文件中放的是:name=\u4e2d\u56fdabc
    则你使用:
    public static Hashtable properties=null; 
    StringUtil st=new StringUtil(); 
    properties=st.loadProperties("/client.properties",'='); String  str1=convert( (String)properties.get("name") ); 
    System.out.println(str1);
    运行结果就是:
    中国abc