Home > database >  Printing a table horizontally
Printing a table horizontally

Time:06-26

I want to know if there's any way to print an array horizontally.

var Tab [] string
Tab=append(Tab,"1")
Tab=append(Tab,"2")
for _,i:=range Tab {
fmt.Println(i)}

This is just a simple example to explain the situation, it would print it this way:

1
2

Instead, I wanted it to be like this:

1 2

CodePudding user response:

  1. Using Println(i) it always print value in a new line.

  2. Then, Use fmt.Printf(i)

package main

import "fmt"

func main() {
   var Tab [] string
    Tab=append(Tab,"1")
    Tab=append(Tab,"2")
    for _,i:=range Tab {
    fmt.Printf(i)}
}

Output is -->> 1 2

CodePudding user response:

You can try this like this: https://go.dev/play/p/mHKo0xFqKCU

Reference: How to print the values of slices

  • Related