NomanAhmed
asked on
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
string str= "\\u0020"
property.setProperty("key"
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
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.showMessageDia log(null,S tring.valu eOf(c),"if ",1);
sb.append("\\u0020" );
//sb.append(c);
} else {
sb.append("\\u0" + Integer.toHexString((int) c).toUpperCase() );
// JOptionPane.showMessageDia log(null,S tring.valu eOf(c),"el se",1);
}
}
return sb.toString();
}
////////////////////////// ////////// ////////// ////////// ////////// ////////// ////////// ////////// ////////// ////
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.showMessageDia
sb.append("\\u0020" );
//sb.append(c);
} else {
sb.append("\\u0" + Integer.toHexString((int) c).toUpperCase() );
// JOptionPane.showMessageDia
}
}
return sb.toString();
}
//////////////////////////
ASKER
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?
propertiesFile.setProperty
so it shuld set the value in property file as
key=\url
but it sets it as
key=\\url
WHY?
code looks fine, problem may be elsewhere
where exactly are you seeing the double slashes.
where exactly are you seeing the double slashes.
> 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.
again, where are you see this.
If its in the Properties file then it is correct, as the back slash must be escaped.
ASKER
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
but then how can i write somthing like "\abc" in property file through setProperty method?
example of a property file:
text=\abc
\abc is not a valid string as \a is not a defined escape sequence
ASKER
example of a property file:
text=\u0646
how can write this using setProperty method????
text=\u0646
how can write this using setProperty method????
as i first posted :)
>>
example of a property file:
text=\u0646
how can write this using setProperty method????
>>
x.setProperty("text", "\\u0646");
example of a property file:
text=\u0646
how can write this using setProperty method????
>>
x.setProperty("text", "\\u0646");
think that should be:
String str= "\u0020"