Solved

unicode character problem

Posted on 2006-11-02
12
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

636 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