Hi, I need to received the special bytes from a URL and convert them
into a java string, can anyone help me
about this? most appreciated for your help.
Eg. http://www..../search_str=%E6%84%9F%E5%86%92
I need convert the utf-8 format %E6%84%9F%E5%86%92 into a java string,
thanks a lot!
Thomas Fritsch - 13 Nov 2007 17:51 GMT
au.danji@gmail.com schrieb:
> Hi, I need to received the special bytes from a URL and convert them
> into a java string, can anyone help me
[quoted text clipped - 4 lines]
> I need convert the utf-8 format %E6%84%9F%E5%86%92 into a java string,
> thanks a lot!
String s =
URLDecoder.decode("http://www..../search_str=%E6%84%9F%E5%86%92","UTF-8");
It produces a String with 2 chinese characters after "search_str=",
namely "http://www..../search_str=\u611F\u5192" when written in Java's
\uxxxx syntax.

Signature
Thomas
John Maline - 13 Nov 2007 18:18 GMT
> Hi, I need to received the special bytes from a URL and convert them
> into a java string, can anyone help me
[quoted text clipped - 4 lines]
> I need convert the utf-8 format %E6%84%9F%E5%86%92 into a java string,
> thanks a lot!
There's a String constructor that takes an array of bytes and the name
of the character set.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#String(byte[],%20j
ava.lang.String)
So it'd be...
String s = new String(myByteArray, "UTF8");
JavaDoc is your friend. If you want to make an instance of class X, the
first place to look is the list of constructors and static (factory)
methods in the javadocs for class X. Not always the right answer for a
question like that, but it's the place to start...
John
Roedy Green - 13 Nov 2007 22:10 GMT
On Tue, 13 Nov 2007 17:04:00 -0000, "au.danji@gmail.com"
<au.danji@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>Hi, I need to received the special bytes from a URL and convert them
>into a java string, can anyone help me
>about this? most appreciated for your help.
see http://mindprod.com/jgloss/conversion.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 13 Nov 2007 22:20 GMT
On Tue, 13 Nov 2007 17:04:00 -0000, "au.danji@gmail.com"
<au.danji@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>I need convert the utf-8 format %E6%84%9F%E5%86%92 into a java string,
>thanks a lot!
That looks like some flavour of armoured utf-8. See
http://mindprod.com/jgloss/armouring.html
It is probably URL-encoded.
see http://mindprod.com/jgloss/urlencoded.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Steven Simpson - 13 Nov 2007 23:01 GMT
> Eg. http://www..../search_str=%E6%84%9F%E5%86%92
>
> I need convert the utf-8 format %E6%84%9F%E5%86%92 into a java string,
> thanks a lot!
Shove it in a java.net.URI, and extract the parts you want. This should
ensure that extraction occurs before decoding, since you don't want to
misinterpret an encoded character as a separator.
For me, this program appears to do the job:
import java.net.*;
public class Decode {
public static void main(String[] args) throws Exception {
for (String a : args) {
URI u = URI.create(a);
System.out.println("Arg: " + a);
System.out.println("URI: " + u);
System.out.println("Scheme: " + u.getScheme());
System.out.println("Authority: " + u.getAuthority());
System.out.println("UserInfo: " + u.getUserInfo());
System.out.println("Host: " + u.getHost());
System.out.println("Port: " + u.getPort());
System.out.println("Path: " + u.getPath());
System.out.println("Query: " + u.getQuery());
System.out.println("Fragment: " + u.getFragment());
}
}
}

Signature
ss at comp dot lancs dot ac dot uk |