Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

unicode character problem

Posted on 2006-11-02
12
Medium Priority
?
259 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 500 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

705 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