Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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
   
0
NomanAhmed
Asked:
NomanAhmed
  • 6
  • 5
1 Solution
 
objectsCommented:
> string str=  "\\u0020"

think that should be:

String str=  "\u0020"
0
 
NomanAhmedAuthor 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
0
 
objectsCommented:
coming from where?

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

char c = (char) Integer.parseInt(s.substring(3), 16);
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
NomanAhmedAuthor 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();
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
0
 
NomanAhmedAuthor 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?
0
 
objectsCommented:
code looks fine, problem may be elsewhere
where exactly are you seeing the double slashes.
0
 
objectsCommented:
> 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.
0
 
NomanAhmedAuthor 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
0
 
objectsCommented:
\abc is not a valid string as \a is not a defined escape sequence
0
 
NomanAhmedAuthor Commented:
example of a property file:

text=\u0646

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

text=\u0646

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

x.setProperty("text", "\\u0646");
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now