doujiao3346 2015-02-26 20:06
浏览 42
已采纳

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

I'm begginer to Go. I'm trying to use blackfriday (a Go Markdown parser). This is the code:

package main

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

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

    fmt.Println(output)
}

I got an error, though:

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

So I tried turning the argument into []byte:

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

This output the bytes though:

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]

How can I print the generated HTML instead of the bytes?

  • 写回答

1条回答 默认 最新

  • douchong4730 2015-02-26 20:29
    关注

    Convert it back to a string.

    fmt.Println(string(output))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部