简体   繁体   中英

Convert string from codepage 1252 to 1250

How can I convert one String with characters decoded in codepage 1252 into a String decoded in codepage 1250.

For example

String str1252 = "ê¹ś¿źæñ³ó";
String str1250 = convert(str1252);
System.out.print(str1250);

I want to find such convert() function, that printed output would be:

ęąśżźćńłó

These are Polish-specific characters.

Thank you for any suggestions.

It's pretty straightforward:

public String convert(String s) {
    return new String(s.getBytes("Windows-1252"), "Windows-1250");
}

Note that System.out.print() can introduce another incorrect conversion due to mismatch between ANSI and OEM code pages . However System.console().writer().print() should output it correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM