We help IT Professionals succeed at work.

unicode character problem

NomanAhmed
NomanAhmed asked
on
Medium Priority
271 Views
Last Modified: 2010-03-31
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
   
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> string str=  "\\u0020"

think that should be:

String str=  "\u0020"

Author

Commented:
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
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
coming from where?

sounds like you'll need to manually decode it, something like:

char c = (char) Integer.parseInt(s.substring(3), 16);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
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();
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////

Author

Commented:
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?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
code looks fine, problem may be elsewhere
where exactly are you seeing the double slashes.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> 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.

Author

Commented:
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
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
\abc is not a valid string as \a is not a defined escape sequence

Author

Commented:
example of a property file:

text=\u0646

how can write this using setProperty method????
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
as i first posted :)
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>
 example of a property file:

text=\u0646

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

x.setProperty("text", "\\u0646");
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.