go1.20.5
GoThrough

strings.Clone

// Clone returns a fresh copy of s. // It guarantees to make a copy of s into a new allocation, // which can be important when retaining only a small substring // of a much larger string. Using Clone can help such programs // use less memory. Of course, since using Clone makes a copy, // overuse of Clone can make programs use more memory. // Clone should typically be used only rarely, and only when // profiling indicates that it is needed. // For strings of length zero the string "" will be returned // and no allocation is made. func Clone(s string) string

strings.Compare

// Compare returns an integer comparing two strings lexicographically. // The result will be 0 if a == b, -1 if a < b, and +1 if a > b. // // Compare is included only for symmetry with package bytes. // It is usually clearer and always faster to use the built-in // string comparison operators ==, <, >, and so on. func Compare(a string, b string) int

strings.Contains

// Contains reports whether substr is within s. func Contains(s string, substr string) bool

strings.ContainsAny

// ContainsAny reports whether any Unicode code points in chars are within s. func ContainsAny(s string, chars string) bool

strings.ContainsRune

// ContainsRune reports whether the Unicode code point r is within s. func ContainsRune(s string, r rune) bool

strings.Count

// Count counts the number of non-overlapping instances of substr in s. // If substr is an empty string, Count returns 1 + the number of Unicode code points in s. func Count(s string, substr string) int

strings.Cut

// Cut slices s around the first instance of sep, // returning the text before and after sep. // The found result reports whether sep appears in s. // If sep does not appear in s, cut returns s, "", false. func Cut(s string, sep string) (before string, after string, found bool)

strings.CutPrefix

// CutPrefix returns s without the provided leading prefix string // and reports whether it found the prefix. // If s doesn't start with prefix, CutPrefix returns s, false. // If prefix is the empty string, CutPrefix returns s, true. func CutPrefix(s string, prefix string) (after string, found bool)

strings.CutSuffix

// CutSuffix returns s without the provided ending suffix string // and reports whether it found the suffix. // If s doesn't end with suffix, CutSuffix returns s, false. // If suffix is the empty string, CutSuffix returns s, true. func CutSuffix(s string, suffix string) (before string, found bool)

strings.EqualFold

// EqualFold reports whether s and t, interpreted as UTF-8 strings, // are equal under simple Unicode case-folding, which is a more general // form of case-insensitivity. func EqualFold(s string, t string) bool

strings.Fields

// Fields splits the string s around each instance of one or more consecutive white space // characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an // empty slice if s contains only white space. func Fields(s string) []string

strings.FieldsFunc

// FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) // and returns an array of slices of s. If all code points in s satisfy f(c) or the // string is empty, an empty slice is returned. // // FieldsFunc makes no guarantees about the order in which it calls f(c) // and assumes that f always returns the same value for a given c. func FieldsFunc(s string, f func(rune) bool) []string

strings.HasPrefix

// HasPrefix tests whether the string s begins with prefix. func HasPrefix(s string, prefix string) bool

strings.HasSuffix

// HasSuffix tests whether the string s ends with suffix. func HasSuffix(s string, suffix string) bool

strings.Index

// Index returns the index of the first instance of substr in s, or -1 if substr is not present in s. func Index(s string, substr string) int

strings.IndexAny

// IndexAny returns the index of the first instance of any Unicode code point // from chars in s, or -1 if no Unicode code point from chars is present in s. func IndexAny(s string, chars string) int

strings.IndexByte

// IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s. func IndexByte(s string, c byte) int

strings.IndexFunc

// IndexFunc returns the index into s of the first Unicode // code point satisfying f(c), or -1 if none do. func IndexFunc(s string, f func(rune) bool) int

strings.IndexRune

// IndexRune returns the index of the first instance of the Unicode code point // r, or -1 if rune is not present in s. // If r is utf8.RuneError, it returns the first instance of any // invalid UTF-8 byte sequence. func IndexRune(s string, r rune) int

strings.Join

// Join concatenates the elements of its first argument to create a single string. The separator // string sep is placed between elements in the resulting string. func Join(elems []string, sep string) string

strings.LastIndex

// LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s. func LastIndex(s string, substr string) int

strings.LastIndexAny

// LastIndexAny returns the index of the last instance of any Unicode code // point from chars in s, or -1 if no Unicode code point from chars is // present in s. func LastIndexAny(s string, chars string) int

strings.LastIndexByte

// LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s. func LastIndexByte(s string, c byte) int

strings.LastIndexFunc

// LastIndexFunc returns the index into s of the last // Unicode code point satisfying f(c), or -1 if none do. func LastIndexFunc(s string, f func(rune) bool) int

strings.Map

// Map returns a copy of the string s with all its characters modified // according to the mapping function. If mapping returns a negative value, the character is // dropped from the string with no replacement. func Map(mapping func(rune) rune, s string) string

strings.NewReader

// NewReader returns a new Reader reading from s. // It is similar to bytes.NewBufferString but more efficient and read-only. func NewReader(s string) *Reader

strings.NewReplacer

// NewReplacer returns a new Replacer from a list of old, new string // pairs. Replacements are performed in the order they appear in the // target string, without overlapping matches. The old string // comparisons are done in argument order. // // NewReplacer panics if given an odd number of arguments. func NewReplacer(oldnew ...string) *Replacer

strings.Repeat

// Repeat returns a new string consisting of count copies of the string s. // // It panics if count is negative or if the result of (len(s) * count) // overflows. func Repeat(s string, count int) string

strings.Replace

// Replace returns a copy of the string 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 Replace(s string, old string, new string, n int) string

strings.ReplaceAll

// ReplaceAll returns a copy of the string 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 ReplaceAll(s string, old string, new string) string

strings.Split

// Split slices s into all substrings separated by sep and returns a slice of // the substrings between those separators. // // If s does not contain sep and sep is not empty, Split returns a // slice of length 1 whose only element is s. // // If sep is empty, Split splits after each UTF-8 sequence. If both s // and sep are empty, Split returns an empty slice. // // It is equivalent to SplitN with a count of -1. // // To split around the first instance of a separator, see Cut. func Split(s string, sep string) []string

strings.SplitAfter

// SplitAfter slices s into all substrings after each instance of sep and // returns a slice of those substrings. // // If s does not contain sep and sep is not empty, SplitAfter returns // a slice of length 1 whose only element is s. // // If sep is empty, SplitAfter splits after each UTF-8 sequence. If // both s and sep are empty, SplitAfter returns an empty slice. // // It is equivalent to SplitAfterN with a count of -1. func SplitAfter(s string, sep string) []string