pad

package module
v0.0.0-...-172aa76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2020 License: BSD-2-Clause Imports: 1 Imported by: 141

README

pad

Build Status

A golang implementation of the left-pad javascript library

I was inspired by Stew's left-cats, who was inspired by this article, to port this to Go.

This implementation will let you pad byte-strings and UTF-8 encoded strings

example usage:

package main

import (
	"fmt"

	"github.com/willf/pad"
	padUtf8 "github.com/willf/pad/utf8"
)

func main() {
	fmt.Println(pad.Right("Hello", 20, "!"))
	fmt.Println(padUtf8.Left("Exit now", 20, "→"))
}
> go run example.go
Hello!!!!!!!!!!!!!!!
→→→→→→→→→→→→Exit now

Documentation

Overview

Package pad provides left-padding functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Left

func Left(str string, length int, pad string) string

Left left-pads the string with pad up to len runes len may be exceeded if

func Right(str string, length int, pad string) string

Right right-pads the string with pad up to len runes

Types

This section is empty.

Directories

Path Synopsis
Package utf8 provides left-padding and right-padding for utf8 strings
Package utf8 provides left-padding and right-padding for utf8 strings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL