英文:
Javascript unescape equivalent in golang?
问题
在Golang中是否有JavaScript的unescape()
函数的等效方法?
JavaScript示例:
package main
import (
"fmt"
"net/url"
)
func main() {
c, _ := url.QueryUnescape("%u0107") // "ć"
fmt.Println(c)
}
在Golang中,可以使用net/url
包中的QueryUnescape()
函数来实现与JavaScript的unescape()
函数类似的功能。以上是一个示例代码,它将%u0107
解码为ć
并打印输出。
英文:
Is there an equivalent of JavaScript's unescape()
in Golang?
JavaScript example:
<script>
var c = unescape('%u0107'); // "ć"
console.log(c);
</script>
答案1
得分: 1
unescape
函数在Mozilla文档[1]中被标记为“已弃用”(红色垃圾桶)。因此,我不建议使用它,也不建议寻找Go语言中的等效函数。Go语言有一个类似的函数[2],但它对输入的要求与您提供的不同:
package main
import "net/url"
func main() {
s, err := url.PathUnescape("%C4%87")
if err != nil {
panic(err)
}
println(s == "ć")
}
如果您真的坚持要这样做,您可以尝试翻译这个polyfill [3]。
- https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/unescape
- https://godocs.io/net/url#PathUnescape
- https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.unescape.js
英文:
The unescape
function is marked as "Deprecated" (red trash can), in the Mozilla documentation [1]. As such, I wouldn't recommend using it, and certainly not seeking out an equivalent Go function. Go has a similar function [2], but it expects different input from what you have provided:
package main
import "net/url"
func main() {
s, err := url.PathUnescape("%C4%87")
if err != nil {
panic(err)
}
println(s == "ć")
}
If you are really set on doing this, you could see about translating this
polyfill [3].
- <https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/unescape>
- https://godocs.io/net/url#PathUnescape
- https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.unescape.js
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论