Solved

unicode character problem

Posted on 2006-11-02
12
255 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
   
0
Comment
Question by:NomanAhmed
  • 6
  • 5
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17856923
> string str=  "\\u0020"

think that should be:

String str=  "\u0020"
0
 

Author Comment

by:NomanAhmed
ID: 17856994
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
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 17857013
coming from where?

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

char c = (char) Integer.parseInt(s.substring(3), 16);
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:NomanAhmed
ID: 17857036
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
 

Author Comment

by:NomanAhmed
ID: 17857052
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
 
LVL 92

Expert Comment

by:objects
ID: 17857067
code looks fine, problem may be elsewhere
where exactly are you seeing the double slashes.
0
 
LVL 92

Expert Comment

by:objects
ID: 17857073
> 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
 

Author Comment

by:NomanAhmed
ID: 17857081
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
 
LVL 92

Expert Comment

by:objects
ID: 17857110
\abc is not a valid string as \a is not a defined escape sequence
0
 

Author Comment

by:NomanAhmed
ID: 17857151
example of a property file:

text=\u0646

how can write this using setProperty method????
0
 
LVL 92

Expert Comment

by:objects
ID: 17857174
as i first posted :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17859209
>>
 example of a property file:

text=\u0646

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

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question