Cover.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace IPADDemo.Util
  8. {
  9. public static class Cover
  10. {
  11. [DllImport("kernel32.dll")]
  12. public static extern int MultiByteToWideChar(int CodePage, int dwFlags, string lpMultiByteStr, int cchMultiByte, [MarshalAs(UnmanagedType.LPWStr)]string lpWideCharStr, int cchWideChar);
  13. /// <summary>
  14. /// 宽字符集转换
  15. /// </summary>
  16. /// <param name="content"></param>
  17. /// <param name="toEncode"></param>
  18. /// <returns></returns>
  19. public static string MByteToWChar(string content, int toEncode)
  20. {
  21. //字符编码转换 GB2312:936   UTF-8:65001  BIG5:950  latin1:1252
  22. int len = Cover.MultiByteToWideChar(toEncode, 0, content, -1, null, 0);
  23. char[] temp = new char[len];
  24. string content1 = new string(temp);
  25. Cover.MultiByteToWideChar(toEncode, 0, content, -1, content1, len);
  26. return content1.Replace("\0", "");
  27. }
  28. }
  29. }