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
+24k Golang : Convert long hexadecimal with strconv.ParseUint example
+6.6k Golang : Lock executable to a specific machine with unique hash of the machine
+13.7k Golang : package is not in GOROOT during compilation
+16.7k How to enable MariaDB/MySQL logs ?
+13.1k Golang : Check if a file exist or not
+12k Golang : Convert IPv4 address to packed 32-bit binary format
+11.5k Golang : Listen and Serve on sub domain example
+22.9k Golang : Upload to S3 with official aws-sdk-go package
+22.6k Golang : Check if element exist in map
+6k How to let Facebook Login button redirect to a particular URL ?
+8.4k Golang : Web(Javascript) to server-side websocket example