Documentation
¶
Overview ¶
Package strings manipulates UTF-8 encoded strings.
Index ¶
- func Compare(a, b string) int
- func Contains(s, substr string) bool
- func ContainsAny(s, chars string) bool
- func ContainsFunc(s string, f func(rune) bool) bool
- func ContainsRune(s string, r rune) bool
- func Count(s, substr string) int
- func Cut(s, sep string) (before, after string, found bool)
- func CutPrefix(s, prefix string) (after string, found bool)
- func CutSuffix(s, suffix string) (before string, found bool)
- func EqualFold(s, t string) bool
- func Fields(s string) []string
- func FieldsFunc(s string, f func(rune) bool) []string
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func Index(s, substr string) int
- func IndexAny(s, chars string) int
- func IndexByte(s string, c byte) int
- func IndexFunc(s string, f func(rune) bool) int
- func IndexRune(s string, r rune) int
- func Join(elems []string, sep string) string
- func LastIndex(s, substr string) int
- func LastIndexAny(s, chars string) int
- func LastIndexByte(s string, c byte) int
- func LastIndexFunc(s string, f func(rune) bool) int
- func Map(mapping func(rune) rune, s string) string
- func Repeat(s string, count int) string
- func Replace(s, old, new string, n int) string
- func ReplaceAll(s, old, new string) string
- func Split(s, sep string) []string
- func SplitAfter(s, sep string) []string
- func SplitAfterN(s, sep string, n int) []string
- func SplitN(s, sep string, n int) []string
- func ToLower(s string) string
- func ToTitle(s string) string
- func ToUpper(s string) string
- func ToValidUTF8(s, replacement string) string
- func Trim(s, cutset string) string
- func TrimFunc(s string, f func(rune) bool) string
- func TrimLeft(s, cutset string) string
- func TrimLeftFunc(s string, f func(rune) bool) string
- func TrimPrefix(s, prefix string) string
- func TrimRight(s, cutset string) string
- func TrimRightFunc(s string, f func(rune) bool) string
- func TrimSpace(s string) string
- func TrimSuffix(s, suffix string) string
- type Builder
- func (b *Builder) Cap() int
- func (b *Builder) Grow(n int)
- func (b *Builder) Len() int
- func (b *Builder) Reset()
- func (b *Builder) String() string
- func (b *Builder) Write(p []byte) (int, error)
- func (b *Builder) WriteByte(c byte) error
- func (b *Builder) WriteRune(r rune) (int, error)
- func (b *Builder) WriteString(s string) (int, error)
- type Reader
- func (r *Reader) Len() int
- func (r *Reader) Read(b []byte) (n int, err error)
- func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadRune() (ch rune, size int, err error)
- func (r *Reader) Reset(s string)
- func (r *Reader) Seek(offset int64, whence int) (int64, error)
- func (r *Reader) Size() int64
- func (r *Reader) UnreadByte() error
- func (r *Reader) UnreadRune() error
- func (r *Reader) WriteTo(w io.Writer) (n int64, err error)
- type Replacer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAny ¶
ContainsAny reports whether any rune of chars is within s.
func ContainsFunc ¶
ContainsFunc reports whether any rune of s satisfies f.
func ContainsRune ¶
ContainsRune reports whether r is within s.
func Count ¶
Count counts the non-overlapping instances of substr in s. An empty substr counts as one more than the number of runes in s.
func FieldsFunc ¶
FieldsFunc splits s around runs of runes satisfying f.
func IndexRune ¶
IndexRune returns the index of the first instance of r in s, or -1. For utf8.RuneError it matches the first invalid byte or encoded U+FFFD.
func LastIndexAny ¶
LastIndexAny returns the index of the last rune of s that is in chars, or -1.
func LastIndexByte ¶
LastIndexByte returns the index of the last instance of c in s, or -1.
func LastIndexFunc ¶
LastIndexFunc returns the index of the last rune satisfying f, or -1.
func Map ¶
Map returns s with every rune mapped by mapping; runes mapped to a negative value are dropped. Invalid UTF-8 bytes are mapped as RuneError.
func Replace ¶
Replace returns s with the first n non-overlapping instances of old replaced by new; n < 0 replaces all. An empty old matches before every rune and at the end.
func ReplaceAll ¶
ReplaceAll replaces every non-overlapping instance of old with new.
func SplitAfter ¶
SplitAfter slices s after each instance of sep.
func SplitAfterN ¶
SplitAfterN slices s after each instance of sep into at most n substrings.
func ToValidUTF8 ¶
ToValidUTF8 replaces each run of invalid UTF-8 bytes with replacement.
func TrimLeftFunc ¶
TrimLeftFunc removes leading runes satisfying f.
func TrimPrefix ¶
TrimPrefix removes prefix from s if present.
func TrimRightFunc ¶
TrimRightFunc removes trailing runes satisfying f.
func TrimSuffix ¶
TrimSuffix removes suffix from s if present.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds a string with appends.
type Reader ¶ added in v0.6.0
type Reader struct {
// contains filtered or unexported fields
}
Reader implements io.Reader, io.ReaderAt, io.Seeker, io.WriterTo, io.ByteScanner and io.RuneScanner over a string. The zero value reads nothing.
func (*Reader) ReadAt ¶ added in v0.6.0
ReadAt implements io.ReaderAt. It does not change the read position.
func (*Reader) UnreadByte ¶ added in v0.6.0
UnreadByte steps back one byte.
func (*Reader) UnreadRune ¶ added in v0.6.0
UnreadRune steps back over the rune returned by the previous ReadRune.
type Replacer ¶
type Replacer struct {
// contains filtered or unexported fields
}
Replacer replaces a list of strings with replacements.
func NewReplacer ¶
NewReplacer returns a Replacer from old, new string pairs. Replacements happen in target string order without overlapping; at the same position, earlier pairs win. It panics on an odd argument count.