pe4enko
pe4enko

Reputation: 354

Windows-1251 to UTF-8 codes

I have code of character in Windows-1251 code table. How i can get code of this character in UTF-8 code table?

For example i have character 'А' with coded in Windows-1251 equals 192, appropriate utf-8 code equals 1040

How i can to initialize Character or char in Java with code 192 from Windows-1251 code table?

char c = (char)192; //how to specify the encoding ?

Upvotes: 4

Views: 8008

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533492

To convert a byte[] encoding in one character encoding to another you can do

public static byte[] convertEncoding(byte[] bytes, String from, String to) {
    return new String(bytes, from).getBytes(to);
}

Upvotes: 8

Related Questions