strings

package
v1.4.11 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 11 Imported by: 30

Documentation

Index

Constants

View Source
const FormatRe = `\{\{([^\}]+)\}\}`

FormatRe is the regular expression for format.

Variables

This section is empty.

Functions

func Contains

func Contains(s, substr string) bool

Contains returns true if s contains substr.

func EndsWith

func EndsWith(s, suffix string) bool

EndsWith returns true if s ends with suffix.

func Equals

func Equals(s, t string) bool

Equals returns true if s1 and s2 are equal.

func Format added in v1.2.14

func Format(pattern string, data map[string]any) string

Format formats a string with template bracket {key}}} and value map.

func HasPrefix

func HasPrefix(s, prefix string) bool

HasPrefix returns true if s starts with prefix.

func HasSuffix

func HasSuffix(s, suffix string) bool

HasSuffix returns true if s ends with suffix.

func IndexOf

func IndexOf(s, substr string) int

IndexOf returns the index of the first occurrence of substr in s, or -1 if substr is not found.

func Join

func Join(a []string, sep string) string

Join joins the elements of a to create a single string. The separator string sep is placed between elements in the resulting string.

func LowerCase

func LowerCase(s string) string

LowerCase returns a copy of s with all uppercase letters converted to lowercase.

func MustToBool

func MustToBool(s string) bool

MustToBool converts a string to a boolean. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.

func MustToFloat

func MustToFloat(s string) float64

MustToFloat converts a string to a float64.

func MustToFloat32

func MustToFloat32(s string) float32

MustToFloat32 converts a string to a float32.

func MustToFloat64

func MustToFloat64(s string) float64

MustToFloat64 converts a string to a float64.

func MustToInt

func MustToInt(s string) int

MustToInt converts a string to an integer.

func MustToInt64

func MustToInt64(s string) int64

MustToInt64 converts a string to an integer.

func PadLeft

func PadLeft(s string, n int, padding string) string

PadLeft ...

func PadRight

func PadRight(s string, n int, padding string) string

PadRight ...

func PadZero

func PadZero(s string, n int) string

PadZero ...

func Random

func Random(n int, seeds ...string) string

Random returns a random string of length n.

func Repeat

func Repeat(s string, n int) string

Repeat returns a new string consisting of n copies of the string s.

func Replace

func Replace(s, old, new string, n int) string

Replace returns a copy of s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.

func ReplaceAll

func ReplaceAll(s, old, new string) string

ReplaceAll returns a copy of s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.

func ReplaceAllFunc

func ReplaceAllFunc(s string, re string, f func([]byte) []byte) string

ReplaceAllFunc returns a copy of s with all non-overlapping instances of the function f applied to old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.

func Slice

func Slice(s string, start int, end ...int) string

Slice returns a substring of s.

func Split

func Split(s, sep string) []string

Split splits a string into a slice of strings.

func SplitN

func SplitN(s, sep string, n int) []string

SplitN splits a string into a slice of strings.

func StartsWith

func StartsWith(s, prefix string) bool

StartsWith returns true if s starts with prefix.

func Template added in v1.2.7

func Template(rawTemplate string, data map[string]any) (builtText string, err error)

Template formats a template string with go template syntax.

func ToBool

func ToBool(s string) (bool, error)

ToBool converts a string to a boolean. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error.

func ToFloat

func ToFloat(s string) (float64, error)

ToFloat converts a string to a float64.

func ToFloat32

func ToFloat32(s string) (float32, error)

ToFloat32 converts a string to a float32.

func ToFloat64

func ToFloat64(s string) (float64, error)

ToFloat64 converts a string to a float64.

func ToInt

func ToInt(s string) (int, error)

ToInt converts a string to an integer.

func ToInt64

func ToInt64(s string) (int64, error)

ToInt64 converts a string to an integer.

func ToLower

func ToLower(s string) string

ToLower returns a copy of s with all uppercase letters converted to lowercase.

func ToTitle

func ToTitle(s string) string

ToTitle returns a copy of the string s with all Unicode letters that begin

func ToUpper

func ToUpper(s string) string

ToUpper returns a copy of s with all lowercase letters converted to uppercase.

func Trim

func Trim(s, cutset string) string

Trim returns a substring of s without leading and trailing cutsets.

func TrimLeft

func TrimLeft(s, cutset string) string

TrimLeft returns a substring of s without leading cutsets.

func TrimPrefix added in v1.3.7

func TrimPrefix(s, prefix string) string

TrimPrefix returns s without the provided leading prefix string.

func TrimRight

func TrimRight(s, cutset string) string

TrimRight returns a substring of s without trailing cutsets.

func TrimSpace

func TrimSpace(s string) string

TrimSpace returns a substring of s without leading and trailing spaces.

func TrimSuffix added in v1.3.7

func TrimSuffix(s, suffix string) string

TrimSuffix returns s without the provided trailing suffix string.

func UpperCase

func UpperCase(s string) string

UpperCase returns a copy of s with all lowercase letters converted to uppercase.

Types

type Builder added in v1.4.11

type Builder interface {
	String() string
	Len() int
	Write(b []byte) (int, error)
	Reset()
}

func NewBuilder added in v1.4.11

func NewBuilder() Builder

type Value

type Value string

Value is the value string to spfcast to new type with spf13/

func (Value) Bool added in v1.2.2

func (s Value) Bool() bool

Bool ...

func (Value) Duration added in v1.2.2

func (s Value) Duration() time.Duration

Duration ...

func (Value) Float64 added in v1.2.2

func (s Value) Float64() float64

Float64 ...

func (Value) Int added in v1.2.2

func (s Value) Int() int

Int ...

func (Value) Int64 added in v1.2.2

func (s Value) Int64() int64

Int64 ...

func (Value) String added in v1.2.2

func (s Value) String() string

String ...

func (Value) Time added in v1.2.2

func (s Value) Time() time.Time

Time ...

func (Value) UInt added in v1.2.2

func (s Value) UInt() uint

UInt ...

func (Value) Uint64 added in v1.2.2

func (s Value) Uint64() uint64

Uint64 ...

Jump to

Keyboard shortcuts

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