• Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting 'ش' to ش

 
Johan Zahri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have this code in a test.jsp:


I accessed the jsp with the following param:

http://localhost:8080/test/test.jsp?q=%26%231588%3B

when i looked at the output of the variable x in the console i get (without spaces):
' & # 1 5 8 8 ; '
what i need is the output:
ش

with the length persumably 1 rather then the 9 characters.

how can i get a String object that contains only ش
in this case if i had the url as above?

Thanks & BR,
Johan
 
Paul Clapham
Sheriff
Posts: 21875
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why you would put Java code into a JSP. And doing URL-decoding on a request parameter is wrong, because the container will already have URL-decoded it. But that doesn't matter for this particular input because the URL-decoding does nothing. If it did something, that would be a bad thing.

Anyway, pick out the substring which represents the number ("1588") and call Integer.parseInt() on it to return the number (1588). Then cast that to a char variable and you're done.
 
Johan Zahri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if there is a utility class that i can reuse. Or a standard way of achiving the desired effect.

If none availabe, for the sake of keeping my sanity.. what would this procedure be called?
would decodeUCS2JavaString be a reasonable name?


 
Paul Clapham
Sheriff
Posts: 21875
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's only a couple of lines of code. As for naming such a method, what you are converting from is an XML numeric character reference. Or maybe an HTML numeric character reference. I have no idea why you're uploading a numeric character reference to your JSP and converting it to the corresponding Unicode code point, so it's hard for me to think of a name for the process.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!