gpt4 book ai didi

Go:在 []byte 函数类型参数中使用字符串?

转载 作者:IT王子 更新时间:2023-10-29 01:59:35 28 4
gpt4 key购买 nike

我刚开始学 Go。我正在尝试使用 blackfriday (Go Markdown 解析器)。这是代码:

package main

import (
"fmt"
"github.com/russross/blackfriday"
)

func main() {
input := "this is a test"
output := blackfriday.MarkdownCommon(input)

fmt.Println(output)
}

不过我遇到了一个错误:

alex@alex-K43U:~/go/src/m2kgo$ go run m2kgo.go
# command-line-arguments
./m2kgo.go:20: cannot use input (type string) as type []byte in argument to blackfriday.MarkdownCommon

所以我尝试将参数转换为[]byte:

output := blackfriday.MarkdownCommon([]byte(input))

虽然这会输出字节:

alex@alex-K43U:~/go/src/m2kgo$ go run m2kgo.go
[60 112 62 116 104 105 115 32 105 115 32 97 32 116 101 115 116 60 47 112 62 10]

如何打印生成的 HTML 而不是字节?

最佳答案

将其转换回字符串。

fmt.Println(字符串(输出))

关于Go:在 []byte 函数类型参数中使用字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28757340/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com