padding

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 2 Imported by: 0

README

go-padding

go-padding generate a padded string according to the specified length. We can specify whether we want string to be padded on the left or the right.

For your reference, we can pad with 0 and spece by using fmt package. Therefore, we don't need use go-padding if you just want to pad with 0 and spece.

Installation

$ go get github.com/mogi86/go-padding

Example Code

package main

import (
	"fmt"
	"github.com/mogi86/go-padding"
)

func main() {
	s := "hello"
	padded, err := padding.Pad(s, 20, "!", padding.PadRight)
	if err != nil {
		fmt.Printf("padding failed: %v\n", err)
	}

	fmt.Printf("padded string: %s\n", padded)
}
  • Output
padded string: hello!!!!!!!!!!!!!!!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pad

func Pad(source string, length int, padStr string, padType PadType) (string, error)

Pad pad string to your string.

Types

type PadType

type PadType int
const (
	// PadLeft is padding type to pad into left side.
	PadLeft PadType = iota
	// PadRight is padding type to pad into right side.
	PadRight
)

Jump to

Keyboard shortcuts

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