Convert string from code page 1252 to 1250

How to convert one Stringwith characters decoded in code page 1252, into String, decoded in code page 1250.

for instance

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

I want to find a function convert()such that the printed output is:

ęąśżźćńłó

These are Polish characters.

Thanks for any suggestions.

+3
source share
1 answer

It is pretty simple:

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

Please note that another incorrect conversionSystem.out.print() may be introduced due to a mismatch between the ANSI and OEM code pages . However, it System.console().writer().print()should output it correctly.

+6
source

Source: https://habr.com/ru/post/1788968/


All Articles