Europa Solo

Europa Solo

  • 2k
  • 8
  • 147

hexToUTF16 international letters (C# WPF)

Sep 20 2020 2:56 PM
I have created a function to convert hex to utf16. It works with english letters, but I also need it to work with international letters.
 
Example hexString=4A006F007200640065006E005F006D00E5006E0065007200000000000000 gives Jorden_m"ner, but I want it to give me Jorden_måner
  1. public String hexToUTF16(String hexString)  
  2. {  
  3.     int length = hexString.Length;  
  4.     byte[] bytes = new byte[length / 2];  
  5.   
  6.     for (int i = 0; i < length; i += 2){  
  7.         bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);  
  8.     }  
  9.   
  10.     char[] chars = Encoding.UTF8.GetChars(bytes);  
  11.   
  12.     string s = new string(chars);  
  13.     s = s.Replace("\0", string.Empty);  
  14.     return s;  
  15. // hexToUTF16 
 

Brought to you by:

Answers (1)