String padding for Go.
import (
"fmt"
"github.com/joshburnsxyz/strpad"
)
func main() {
myPaddedString := strpad.Pad("Hello, world.")
fmt.Println(myPaddedString)
// "Hello, world." becomes " Hello, world. "
}
The Pad()
function can be swapped out for PadLeft()
or PadRight()
using
the identical API to pad the left or right side of a string without the other.
There are also other functions for padding that follow this naming convention.
PadSymbol
andPadNSymbol
functions, take an extra param as a string, and use that to pad the input string.
import (
"fmt"
"github.com/joshburnsxyz/strpad"
)
func main() {
myPaddedString := strpad.PadN("Hello, world.", 2)
fmt.Println(myPaddedString)
// "Hello, world." becomes " Hello, world. "
symbolPaddedStr := strpad.PadSymbol("Hello, world.", "**")
fmt.Println(symbolPaddedStr)
// "Hello, world." becomes "**Hello, world.**"
}
The complete API documentation can be found on pkg.go.dev
go get github.com/joshburnsxyz/strpad
This software is open-sourced under the MIT license.