Skip to content
Node: s.padStart(n, ch)github.com/sahilkhaire/gox/str

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) string

Compare: Node.js · Standard Go · gox

js
s.padStart(8, '0');
go
s = fmt.Sprintf("%*s", width, s) // or custom padding
go
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

Back to str package overview

MIT Licensed · Built for Node.js developers moving to Go