Help us shape the future of Go! Take the 2026 Go Developer Survey

strings

package
v2.38.5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capitalize added in v2.29.8

func Capitalize(s string) string

Capitalize returns s with its first rune upper-cased. It is safe for multi-byte UTF-8 characters, unlike naive byte-slicing approaches.

func EmptyToNil added in v2.29.0

func EmptyToNil(s string) *string

EmptyToNil returns a `nil` for an empty string, or a pointer to the string otherwise. Useful when needing to treat zero values as nil in APIs.

func JoinWithConjunction

func JoinWithConjunction(s []string) string

JoinWithConjunction joins a slice of strings with commas except for the last two which are joined with "and".

func Truncate added in v2.5.0

func Truncate(s string, n int, opts ...TruncateOption) string

Truncate truncates s to n runes. Additional behaviors can be specified using TruncateOptions.

func UISanitize added in v2.25.0

func UISanitize(in string) string

UISanitize sanitizes a string for display in the UI. The following transformations are applied, in order: - HTML tags are removed using bluemonday's strict policy. - ANSI escape codes are stripped using stripansi. - Consecutive backslashes are replaced with a single backslash. - Non-printable characters are removed. - Whitespace characters are replaced with spaces. - Multiple spaces are collapsed into a single space. - Leading and trailing whitespace is trimmed.

Types

type TruncateOption added in v2.27.1

type TruncateOption int
const (
	// TruncateWithEllipsis adds a Unicode ellipsis character to the end of the string.
	TruncateWithEllipsis TruncateOption = 1 << 0
	// TruncateWithFullWords ensures that words are not split in the middle.
	// As a special case, if there is no word boundary, the string is truncated.
	TruncateWithFullWords TruncateOption = 1 << 1
)

func (TruncateOption) String added in v2.27.1

func (o TruncateOption) String() string

Jump to

Keyboard shortcuts

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