Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Go:在循环中附加字节片_Arrays_Go - Fatal编程技术网

Arrays Go:在循环中附加字节片

Arrays Go:在循环中附加字节片,arrays,go,Arrays,Go,我是新来围棋的,所以如果这个问题已经得到了回答,我很抱歉,我正试图在围棋中添加一个字节片,但我没有找到解决方案。我需要分割文件的第一行,我已经这样做了;并将其余的写入一个字节片,以便在事实发生后进行解析。到目前为止,代码如下所示: // Here we extract the first line to name our title and category var title, category string var content []byte in, err := os.Open(file

我是新来围棋的,所以如果这个问题已经得到了回答,我很抱歉,我正试图在围棋中添加一个字节片,但我没有找到解决方案。我需要分割文件的第一行,我已经这样做了;并将其余的写入一个字节片,以便在事实发生后进行解析。到目前为止,代码如下所示:

// Here we extract the first line to name our title and category
var title, category string
var content []byte
in, err := os.Open(file)
utils.CheckErr(err, "could not open file: "+file)
defer in.Close()
// open file
scanner := bufio.NewScanner(in)
lineCount := 1
for scanner.Scan() {
    if lineCount == 1 {
        // assign title and category
        splitString := strings.Split(scanner.Text(), "::")
        title = splitString[0]
        category = splitString[1]
        fmt.Println("title: " + title + "category" + category) // usage to prevent compiler whine
    } else {
        // push the rest into an array to be parsed as jade
        line := scanner.Bytes()
        content = append(content, line) // The question is what goes here?
    }
    lineCount++
}
我尝试过使用append,但这只会给我一个错误
无法在append中将line(type[]byte)用作type byte

我相信您只是在寻找
content=append(content,line…)

我相信您只是在寻找<代码>内容=附加(内容,行…)

请参见

可能有一个复制品,但在我找到之前

您的问题可以通过在
行的末尾添加“…”来解决,因此它看起来像:

content = append(content, line...)

可能有一个复制品,但在我找到之前

您的问题可以通过在
行的末尾添加“…”来解决,因此它看起来像:

content = append(content, line...)

啊哈!谢谢你,似乎已经做到了:)@Nick np。顺便说一句,这方面的文件在这里;现在看来很明显,但不知怎么的,我就是不明白。谢谢大家,你太棒了:)啊哈!谢谢你,似乎已经做到了:)@Nick np。顺便说一句,这方面的文件在这里;现在看来很明显,但不知怎么的,我就是不明白。谢谢大家,你太棒了:)