为什么我不能在代码中直接使用unicode字符串文字 [英] Why can't I use unicode string literals directly in my code

查看:70
本文介绍了为什么我不能在代码中直接使用unicode字符串文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows XP,并且支持我的语言乌尔都语.IDE是JCreator.我面临的问题是,对于我的项目而言,如果我能够直接在代码中使用乌尔都语文本,那将非常容易,但是不幸的是它无法正常工作.任何帮助将不胜感激.

I am using Windows XP with support for my language Urdu. IDE is JCreator. The problem that I am facing is that for my project it would be far easy if I'm able to use Urdu text directly in my code but unfortunately it is not working. Any help would be appreciated.

//urWord是方法参数中的任何单词

//urWord is any word in the method argument

    String s = "\u0628\u0627\u067e";
    String trial = "باپ";

    int comparison = s.compareTo(urWord);
    System.out.println (urWord);
    System.out.println (comparison);

    //works perfectly
    if(s.equals(urWord)){

        System.out.println ("Strings are equal");
    }

    //does not work
    if(s.equals(trial)){

        System.out.println ("Strings are equal");
    }

推荐答案

如果您的文件使用Unicode指定编码的任何形式进行编码,则此方法应该起作用.因此,请在用于Java源代码的编码上检查IDE的配置.

If your files are encoded with any flavor of Unicode-specified encoding, this should work. So check your IDE's configuration on the encoding used for Java source code.

这篇关于为什么我不能在代码中直接使用unicode字符串文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆