doujiao3346 2015-02-27 04: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-27 04:29
    关注

    Convert it back to a string.

    fmt.Println(string(output))

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

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)