Previous: Declaring Variables, Up: The First Echo Command using a for
Loop [Index]
Join
in the strings
PackageIf the amount of data involved is large, this could be costly. A simpler and
more efficient solution would be to use the Join
function from the strings
package:
// Echo3 uses Join function to create a string package main import("fmt";"os";"strings") func main() { fmt.Println(strings.Join(os.Args[1:], " ")) fmt.Println(os.Args[1:]) }
Finally, if we don’t care about format but just want to see the values, perhaps
for debugging, we can let Println
format the results for us:
fmt.Println(os.Args[1:])
The output of this statement is like what we would get from strings.Join
, but
with surrounding brackets. Any slice may be printed this way.