Link to home
Start Free TrialLog in
Avatar of NomanAhmed
NomanAhmed

asked on

unicode character problem

I am facing a problem of using properties file object , what I am doing is that I am calling the setProperty method to set value
string str=  "\\u0020"
property.setProperty("key",str);
and after that I save that into a file when It is stored in a file. The value "\\u0020" should change to \u0020 one \ should be removed but it does not, please explain what is the problem
I am using unicode code character to display arabic
   
Avatar of Mick Barry
Mick Barry
Flag of Australia image

> string str=  "\\u0020"

think that should be:

String str=  "\u0020"
Avatar of NomanAhmed
NomanAhmed

ASKER

but the problem is that string is coming in a format "\\u0624c" I have to convert it \u0624c and then store it in a file
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i m using the following method to convert it:
but this method returns an extra "\" (backslash)
for example it should return \u0646 but it returns \\u0646

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public  String native2ascii(String s) {
        StringBuffer sb = new StringBuffer(s.length() + 80);
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            //if (c <= 0xff) {
            if (c ==' ') {
                //  JOptionPane.showMessageDialog(null,String.valueOf(c),"if",1);
                sb.append("\\u0020" );
                //sb.append(c);
            } else {
                sb.append("\\u0" + Integer.toHexString((int) c).toUpperCase() );
                // JOptionPane.showMessageDialog(null,String.valueOf(c),"else",1);
            }
        }
        return sb.toString();
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
Furthermore the following setProperty method is not workin correctly:

propertiesFile.setProperty("key","\\abc");

so it shuld set the value in property file as

key=\url

but it sets it as

key=\\url

WHY?
code looks fine, problem may be elsewhere
where exactly are you seeing the double slashes.
> key=\\url

again, where are you see this.
If its in the Properties file then it is correct, as the back slash must be escaped.
yes in properties file.

but then how can i write somthing like "\abc" in property file through setProperty method?

example of a property file:

text=\abc
\abc is not a valid string as \a is not a defined escape sequence
example of a property file:

text=\u0646

how can write this using setProperty method????
as i first posted :)
>>
 example of a property file:

text=\u0646

how can write this using setProperty method????
>>

x.setProperty("text", "\\u0646");