convert.go 427 B

1234567891011121314151617181920212223
  1. package cmd
  2. import "golang.org/x/text/encoding/simplifiedchinese"
  3. /*
  4. description:convert the command`s stdout byte data to string
  5. */
  6. func ConvertByte2String(byte []byte, charset string) string {
  7. var str string
  8. switch charset {
  9. case "GB18030":
  10. decodeBytes, _ := simplifiedchinese.GB18030.NewDecoder().Bytes(byte)
  11. str = string(decodeBytes)
  12. case "UTF-8":
  13. fallthrough
  14. default:
  15. str = string(byte)
  16. }
  17. return str
  18. }