byte array to string conversion

Lars Andersen lars@rimfaxe.com
Thu Sep 11 20:24:00 GMT 2003


Tom Tromey wrote:
>>>>>>"Lars" == Lars Andersen <lars@rimfaxe.com> writes:
>>>>>>>>>>>>>>Lars> Just tried it with the latest 3.4 snapshot. Same thing.
>>I suspect your system's iconv(), or your locale setting, or both.
>>Try debugging the program with gdb. My theory is that the early
>`test_str.getBytes()' call is returning bad results.
>>Tom
>>
Well, if I replace toAsciiString with another implementation it works fine.
Like this :
public static final String toAsciiString(byte[] buffer, int startPos, 
int length)
{
 byte[] stringBytes = new byte[length];
 int endIndex = startPos + length;
 int pos = 0;
 for (int i = startPos; i < endIndex; i++)
 {
 stringBytes[pos++] = buffer[i];
 }
 return new String(stringBytes); 
}
But I guess you could be right on the locale thing, since I use both 
english and danish settings.
Investigating now ....
/Lars Andersen


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /