dongpai2468
dongpai2468
2018-12-06 08:00

如何优雅地将一个数组的一部分复制到另一个数组中或注入到另一个数组中

  • insert
  • arrays

I have the following code which works but the point here is that I want to inject or insert one array of arbitrary length into another statically sized array extending its length:

package main

import (
    "fmt"
)

func main() {
    ffmpegArguments := []string{
        "-y",
        "-i", "invideo",
        // ffmpegAudioArguments...,
        "-c:v", "copy",
        "-strict", "experimental",
        "outvideo",
    }

    var outputArguments [12]string
    copy(outputArguments[0:3], ffmpegArguments[0:3])
    copy(outputArguments[3:7], []string{"-i", "inaudio", "-c:a", "aac"})
    copy(outputArguments[7:12], ffmpegArguments[3:8])

    fmt.Printf("%#v
", ffmpegArguments)
    fmt.Printf("%#v
", outputArguments)
}

https://play.golang.org/p/peQXkOpheK4

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答