Golang text/tabwriter.NewWriter() function and Write() method example
package text/tabwriter
Golang text/tabwriter.NewWriter() function and Write() method usage example
Example 1 :
// The tabwriter here helps us generate aligned output.
w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
Example 2:
package main
import (
"fmt"
"os"
"text/tabwriter"
)
func main() {
w := new(tabwriter.Writer)
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
w.Write([]byte("abcd-"))
fmt.Fprintln(w, "a\tb\tc\td\t.")
fmt.Fprintln(w, "123\t12345\t1234567\t123456789\t.")
fmt.Fprintln(w)
w.Flush()
}
References :
Advertisement
Something interesting
Tutorials
+19.9k Golang : Measure http.Get() execution time
+28.6k Get file path of temporary file in Go
+21.8k SSL : How to check if current certificate is sha1 or sha2
+18.6k Golang : Iterating Elements Over A List
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+7.9k Javascript : Put image into Chrome browser's console
+16.9k Golang : How to generate QR codes?
+11.8k Golang : convert(cast) float to string
+6.1k Golang : Measure execution time for a function
+4.7k Linux/MacOSX : How to symlink a file?
+19.8k Golang : Append content to a file
+16.1k Golang : How to check if input from os.Args is integer?