ellipsis

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 0 Imported by: 24

README

ellipsis

Go modules to insert an ellipses into the middle of a long string to shorten it.

Install

go get github.com/jftuga/ellipsis

License

MIT License

Example

package main

import (
	"fmt"
	"github.com/jftuga/ellipsis"
)

func main() {
	s := "abcdefghijklmnopqurstvwxyz"
	for i := 0; i <= 26; i++ {
		s := ellipsis.Shorten(s, i)
		fmt.Printf("%2d %s\n", i, s)
	}
}

Output

 0 
 1 z
 2 yz
 3 xyz
 4 ...z
 5 a...z
 6 a...yz
 7 ab...yz
 8 ab...xyz
 9 abc...xyz
10 abc...wxyz
11 abcd...wxyz
12 abcd...vwxyz
13 abcde...vwxyz
14 abcde...tvwxyz
15 abcdef...tvwxyz
16 abcdef...stvwxyz
17 abcdefg...stvwxyz
18 abcdefg...rstvwxyz
19 abcdefgh...rstvwxyz
20 abcdefgh...urstvwxyz
21 abcdefghi...urstvwxyz
22 abcdefghi...qurstvwxyz
23 abcdefghij...qurstvwxyz
24 abcdefghij...pqurstvwxyz
25 abcdefghijk...pqurstvwxyz
26 abcdefghijklmnopqurstvwxyz

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shorten

func Shorten(s string, w int) string

Shorten will insert "..." into the middle of a long string to shorten it to a length of w

Types

This section is empty.

Directories

Path Synopsis
main.go -John Taylor Dec-31-2020 Insert an ellipses into the middle of a long string to shorten it
main.go -John Taylor Dec-31-2020 Insert an ellipses into the middle of a long string to shorten it

Jump to

Keyboard shortcuts

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