Issue1818393
Created on 2007-10-23.08:49:18 by larrylau, last changed 2007-11-25.19:47:19 by cgroves.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2007-10-23 08:49:18 | larrylau | create | |
Created on 2007-10-23.08:49:18 by larrylau, last changed 2007-11-25.19:47:19 by cgroves.
| Messages | |||
|---|---|---|---|
| msg1998 (view) | Author: larry (larrylau) | Date: 2007-10-23.08:49:18 | |
such as
/**
* @return a byte array with one byte for each char in s. Each byte contains
* the low-order bits of its corresponding char.
*/
public static byte[] to_bytes(String s) {
int len = s.length();
byte[] b = new byte[len];
s.getBytes(0, len, b, 0);
return b;
}
=============>
return s.getBytes();
more better?
|
|||
| msg1999 (view) | Author: Philip Jenvey (pjenvey) | Date: 2007-11-17.01:02:28 | |
This was changed to use String.getBytes('ISO-8859-1') in r3668-3669
|
|||
| msg2000 (view) | Author: larry (larrylau) | Date: 2007-11-21.13:44:56 | |
Why used String.getBytes('ISO-8859-1')?
In fact,its same as s.getBytes(0, len, b, 0).
It appear confused characters when i using in Embedded mode.
|
|||
| msg2001 (view) | Author: Charlie Groves (cgroves) | Date: 2007-11-25.19:47:19 | |
Each character in a Python str is a single byte, so its values can only range from 0-255. String.getBytes("ISO-8859-1") is the fastest way to turn a java String into a byte[] of those values. String.getBytes() uses the JVM's default charset to encode those values to bytes, so it can lead to incorrect byte values if that encoding does something odd with the values. If you have a String with characters beyond 255 in it, you should use a unicode object, not a str.
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2007-10-23 08:49:18 | larrylau | create | |
Supported by Python Software Foundation,
Powered by Roundup