title: Converting a Java String to Windows-1258
body: <p>A special request to all of the Vietnamese natives out there ;-).</p>
  
  <p>I am trying to convert a plain Java String to a byte array using the <a href="https://en.wikipedia.org/wiki/Windows-1258" rel="nofollow">Windows-1258</a> code page. The content in this String is in Vietnamese but that should not be much of a problem seeing as Windows-1258 was designed with Vietnamese in mind. Sadly though, certain characters are not being converted properly.</p>
  
  <p>My test case:</p>
  
  <pre><code>final Charset wcp1258 = Charset.forName("Cp1258");
  
  final String text = "Việt là khó khăn";
  byte[] textArr = text.getBytes(wcp1258);
  
  for (int i = 0; i &lt; textArr.length; i++) {
      System.out.println(String.format("'%s' maps to: 0x%x", text.charAt(i), textArr[i]));
  }
  </code></pre>
  
  <p>Which ends up being:</p>
  
  <pre>'V' maps to: 0x56
  'i' maps to: 0x69
  'ệ' maps to: 0x3f &lt;--
  't' maps to: 0x74
  ' ' maps to: 0x20
  'l' maps to: 0x6c
  'à' maps to: 0xe0
  ' ' maps to: 0x20
  'k' maps to: 0x6b
  'h' maps to: 0x68
  'ó' maps to: 0xf3
  ' ' maps to: 0x20
  'k' maps to: 0x6b
  'h' maps to: 0x68
  'ă' maps to: 0xe3
  'n' maps to: 0x6e</pre>
  
  <p>Where you can see that one character is mapped to <code>3f</code>, which is the question mark in <a href="https://en.wikipedia.org/wiki/Windows-1258" rel="nofollow">Windows-1258</a>.</p>
  
  <p>I have done a little research and have found out that Windows-1258 creates certain characters by combining diacritical marks. Exactly one of these characters got mapped to the question mark.</p>
  
  <p>How do I get this to convert properly? I think the problem may be related to there not being valid conversions for certain unicode characters to the combinations that are required for Windows-1258. I have tried to add the <code>Normalizer</code> class to the mix but without much success.</p>
  
  <p>In case you are wondering, I need this encoding to control a receipt printer. The receipt printer takes either a Windows-1258 or TCVN3 byte array for Vietnamese.</p>