MyEncoding.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ToolsClassLibrary
  7. {
  8. /// <summary>
  9. /// 自定义编码转换 ASCII UTF_8
  10. /// </summary>
  11. public static class MyEncoding
  12. {
  13. /// <summary>
  14. /// 编码ASCII
  15. /// </summary>
  16. /// <param name="buf"></param>
  17. /// <returns></returns>
  18. public static byte[] EncodingASCII(string buf)
  19. {
  20. byte[] data = Encoding.Unicode.GetBytes(buf);
  21. return data;
  22. }
  23. /// <summary>
  24. /// 解码ASCII
  25. /// </summary>
  26. /// <param name="bt"></param>
  27. /// <returns></returns>
  28. public static string DecodingASCII(byte[] bt)
  29. {
  30. string st = Encoding.Unicode.GetString(bt);
  31. return st;
  32. }
  33. /// <summary>
  34. /// 编码UTF_8
  35. /// </summary>
  36. /// <param name="buf"></param>
  37. /// <returns></returns>
  38. public static byte[] EncodingUTF_8(string buf)
  39. {
  40. byte[] data = Encoding.UTF8.GetBytes(buf);
  41. return data;
  42. }
  43. /// <summary>
  44. /// 编码UTF_8
  45. /// </summary>
  46. /// <param name="bt"></param>
  47. /// <returns></returns>
  48. public static string DecodingUTF_8(byte[] bt)
  49. {
  50. string st = Encoding.UTF8.GetString(bt);
  51. return st;
  52. }
  53. }
  54. }