Convert.cs 673 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. /// <summary>
  6. /// 类型转换相关工具集
  7. /// </summary>
  8. public partial class Utils
  9. {
  10. /// <summary>
  11. /// 字符串转字节
  12. /// </summary>
  13. /// <param name="str"></param>
  14. /// <returns></returns>
  15. public static byte[] Str2Bytes(string str)
  16. {
  17. return System.Text.Encoding.UTF8.GetBytes(str);
  18. }
  19. /// <summary>
  20. /// 字节转字符串
  21. /// </summary>
  22. /// <param name="bytes"></param>
  23. /// <returns></returns>
  24. public static string Bytes2Str(byte[] bytes)
  25. {
  26. return System.Text.Encoding.UTF8.GetString(bytes);
  27. }
  28. }