Solved

unicode character problem

Posted on 2006-11-02
12
257 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

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

752 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