[Golang] Fixed Width/Length String Output fixed width/length string in Golang (Go programming language). Source code (Run Code on Go Playground): fixedwidth.go | repository | view raw 1 2 3 4 5 6 7 8package fixedwidth import "fmt" func FixedLengthString(length int, str string) string { verb := fmt.Sprintf("%%%d.%ds", length, length) return fmt.Sprintf(verb, str) } fixedwidth_test.go | repository | view raw 1 2 3 4 5 6 7 8 9 10package fixedwidth import "testing" func TestFixedLengthString(t *testing.T) { println(FixedLengthString(20, "This is")) println(FixedLengthString(20, "an example of")) println(FixedLengthString(20, "fixed width/length")) println(FixedLengthString(20, "string")) } Tested on: Ubuntu Linux 15.10, Go 1.6.2. References: [1] golang format output fixed width - Google search go - How to create a fixed length text file in Golang? - Stack Overflow [2] go fmt to string - Google search go - Golang: format a string without printing? - Stack Overflow [3]Tabby: A tiny library for super simple GoLang tables : golang