PadStart
Overview
PadStart pads s on the left to length with pad (String.padStart).
If you are coming from Node.js, the closest pattern is s.padStart(n, ch).
Signature
go
func PadStart(s string, length int, pad string) stringCompare: Node.js · Standard Go · gox
js
s.padStart(8, '0');go
s = fmt.Sprintf("%*s", width, s) // or custom paddinggo
import "github.com/sahilkhaire/gox/str"
s := str.PadStart("42", 8, "0")Example
go
import "github.com/sahilkhaire/gox/str"
s := str.PadStart("42", 8, "0")Tips
Import github.com/sahilkhaire/gox/str and call PadStart directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
s = fmt.Sprintf("%*s", width, s) // or custom padding