1 回答
TA贡献1816条经验 获得超6个赞
刚刚使用这个功能来解决这个问题。仅供参考,我使用此方法从 HTML 请求中解析分号查询参数(:
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
rawString := "Hello World"
myStringBytes := fmt.Sprint([]byte(rawString))
myResultString, _ := string(StringBytesParseString(myStringBytes))
fmt.Println(myResultString)
fmt.Println(rawString)
}
func StringBytesParseString(byteString string) (string, error) {
byteString = strings.TrimSuffix(byteString, "]")
byteString = strings.TrimLeft(byteString, "[")
sByteString := strings.Split(byteString, " ")
var res []byte
for _, s := range sByteString {
i, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return "", err
}
res = append(res, byte(i))
}
return string(res), nil
}
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报