Documentation ¶
Index ¶
- Constants
- func CamelCase(s string) string
- func Capitalize(s string) string
- func ChecksFunc(s string, f func(rune) bool) bool
- func Clone(s string) string
- func Compare(a, b string) int
- func CompareFold(s, t string) int
- func Contains(s, substr string) bool
- func ContainsAny(s, chars string) bool
- func ContainsByte(s string, b byte) bool
- func ContainsFold(s, substr 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 CountAny(s, chars string) int
- func CountByte(s string, b byte) int
- func CountFunc(s string, f func(rune) bool) int
- func CountRune(s string, c rune) int
- func Cut(s, sep string) (before, after string, found bool)
- func CutAny(s string, chars string) (before, after string, found bool)
- func CutAt(s string, p int) (before, after string)
- func CutByte(s string, sep byte) (before, after string, found bool)
- func CutFunc(s string, f func(rune) bool) (before, after string, found bool)
- func CutPrefix(s, prefix string) (after string, found bool)
- func CutRune(s string, sep rune) (before, after string, found bool)
- func CutSuffix(s, suffix string) (before string, found bool)
- func EndsWith(s, suffix string) bool
- func EndsWithByte(s string, b byte) bool
- func EndsWithFold(s, suffix string) bool
- func EqualFold(s, t string) bool
- func Fields(s string) []string
- func FieldsAny(s, chars string) []string
- func FieldsByte(s string, c byte) []string
- func FieldsFunc(s string, f func(rune) bool) []string
- func FieldsFuncIter(s string, f func(rune) bool, iter func(string) bool)
- func FieldsRune(s string, r rune) []string
- func HasLowerCase(s string) bool
- func HasMultibyte(s string) bool
- func HasPrefix(s, prefix string) bool
- func HasPrefixFold(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func HasSuffixFold(s, suffix string) bool
- func HasUpperCase(s string) bool
- func HasWhitespace(s string) bool
- func If(b bool, t, f string) string
- func IfEmpty(a, b string) string
- func Index(s, substr string) int
- func IndexAny(s, chars string) int
- func IndexByte(s string, c byte) int
- func IndexFold(s, substr string) int
- func IndexFunc(s string, f func(rune) bool) int
- func IndexRune(s string, r rune) int
- func IsASCII(s string) bool
- func IsASCIIPrintable(s string) bool
- func IsDecimal(s string) bool
- func IsEmpty(s string) bool
- func IsHexadecimal(s string) bool
- func IsLetter(s string) bool
- func IsLetterNumber(s string) bool
- func IsLowerCase(s string) bool
- func IsNotEmpty(s string) bool
- func IsNumber(s string) bool
- func IsNumeric(s string) bool
- func IsUTFDigit(s string) bool
- func IsUTFLetter(s string) bool
- func IsUTFLetterNumber(s string) bool
- func IsUTFNumber(s string) bool
- func IsUTFNumeric(s string) bool
- func IsUTFPrintable(s string) bool
- func IsUpperCase(s string) bool
- func IsWhitespace(s string) bool
- func Join(elems []string, sep string) string
- func JoinInt64s(elems []int64, sep string, fmt ...func(int64) string) string
- func JoinInts(elems []int, sep string, fmt ...func(int) string) string
- func LastCut(s, sep string) (before, after string, found bool)
- func LastCutAny(s string, chars string) (before, after string, found bool)
- func LastCutByte(s string, sep byte) (before, after string, found bool)
- func LastCutFunc(s string, f func(rune) bool) (before, after string, found bool)
- func LastCutRune(s string, sep rune) (before, after string, found bool)
- func LastIndex(s, substr string) int
- func LastIndexAny(s, chars string) int
- func LastIndexByte(s string, c byte) int
- func LastIndexFold(s, substr string) int
- func LastIndexFunc(s string, f func(rune) bool) int
- func LastIndexRune(s string, r rune) int
- func Left(s string, n int) string
- func Map(mapping func(rune) rune, s string) string
- func Mid(s string, p, n int) string
- func PadCenter(s string, size int, p string) string
- func PadCenterByte(s string, size int, b byte) string
- func PadCenterRune(s string, size int, c rune) string
- func PadLeft(s string, size int, p string) string
- func PadLeftByte(s string, size int, b byte) string
- func PadLeftRune(s string, size int, r rune) string
- func PadRight(s string, size int, p string) string
- func PadRightByte(s string, size int, b byte) string
- func PadRightRune(s string, size int, r rune) string
- func PascalCase(s string) string
- func RandLetterNumbers(size int) string
- func RandLetters(size int) string
- func RandLowerLetters(size int) string
- func RandNumbers(size int) string
- func RandString(size int, chars ...string) string
- func RandSymbols(size int) string
- func RandUpperLetters(size int) string
- func Remove(s string, r string) string
- func RemoveAny(s string, r string) string
- func RemoveByte(s string, b byte) string
- func RemoveEmpties(ss []string) []string
- func RemoveFunc(s string, f func(r rune) bool) string
- func RemoveRune(s string, r rune) string
- func Removes(ss []string, v string) []string
- func Repeat(s string, count int) string
- func RepeatByte(b byte, count int) string
- func RepeatRune(r rune, count int) string
- func Replace(s, old, new string, n int) string
- func ReplaceAll(s, old, new string) string
- func ReplaceFunc(s string, f func(rune) rune) string
- func Right(s string, n int) string
- func RuneCount(s string) int
- func RuneEqualFold(sr, tr rune) bool
- func RuneLen(r rune) int
- func SkipBOM(s string) string
- func SnakeCase(s string) string
- func SnakeCaseWithRune(s string, d rune) string
- func Split(s, sep string) []string
- func SplitAfter(s, sep string) []string
- func SplitAfterN(s, sep string, n int) []string
- func SplitAny(s, chars string) []string
- func SplitCount(s string, n int) []string
- func SplitFunc(s string, f func(rune) bool) []string
- func SplitLength(s string, n int) []string
- func SplitN(s, sep string, n int) []string
- func StartsWith(s, prefix string) bool
- func StartsWithByte(s string, b byte) bool
- func StartsWithFold(s, prefix string) bool
- func Strip(s string) string
- func StripLeft(s string) string
- func StripLefts(ss []string) []string
- func StripRight(s string) string
- func StripRights(ss []string) []string
- func Strips(ss []string) []string
- func SubstrAfter(s string, b string) string
- func SubstrAfterAny(s string, b string) string
- func SubstrAfterByte(s string, b byte) string
- func SubstrAfterLast(s string, b string) string
- func SubstrAfterLastAny(s string, b string) string
- func SubstrAfterLastByte(s string, b byte) string
- func SubstrAfterLastRune(s string, r rune) string
- func SubstrAfterRune(s string, r rune) string
- func SubstrBefore(s string, b string) string
- func SubstrBeforeAny(s string, b string) string
- func SubstrBeforeByte(s string, b byte) string
- func SubstrBeforeLast(s string, b string) string
- func SubstrBeforeLastAny(s string, b string) string
- func SubstrBeforeLastByte(s string, b byte) string
- func SubstrBeforeLastRune(s string, r rune) string
- func SubstrBeforeRune(s string, r rune) string
- func ToLower(s string) string
- func ToLowerSpecial(c unicode.SpecialCase, s string) string
- func ToLowers(ss []string) []string
- func ToTitle(s string) string
- func ToTitleSpecial(c unicode.SpecialCase, s string) string
- func ToUpper(s string) string
- func ToUpperSpecial(c unicode.SpecialCase, s string) string
- func ToUppers(ss []string) []string
- func ToValidUTF8(s, replacement string) string
- func ToValidUTF8s(ss []string, replacement string) []string
- func Trim(s string, cutset string) string
- func TrimAny(s string, cutset string) string
- func TrimFunc(s string, f func(rune) bool) string
- func TrimLeft(s string, cutset string) string
- func TrimLeftFunc(s string, f func(rune) bool) string
- func TrimPrefix(s, prefix string) string
- func TrimRight(s string, cutset string) string
- func TrimRightFunc(s string, f func(rune) bool) string
- func TrimSpace(s string) string
- func TrimSpaces(ss []string) []string
- func TrimSuffix(s, suffix string) string
- func UnsafeBytes(s string) []byte
- func UnsafeString(bs []byte) string
- type Builder
- type Reader
- type Replacer
Constants ¶
const ( // LowerLetters A String for lower letters "a-z" LowerLetters = "abcdefghijklmnopqrstuvwxyz" // Letters A String for upper letters "A-Z" UpperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // Letters A String for letters "a-zA-Z" Letters = LowerLetters + UpperLetters // Numbers A String for numbers "0123456789" Numbers = "0123456789" // Symbols A String for symbols "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" Symbols = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" // LetterNumbers A String for letters and numbers LetterNumbers = Letters + Numbers // SymbolNumbers A String for symbols and numbers "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~0123456789" SymbolNumbers = Symbols + Numbers // LetterDigitSymbols A String for letters, numbers and symbols LetterDigitSymbols = Symbols + Letters + Numbers // Base64 a-zA-Z0-9+/ Base64 = LetterNumbers + "+/" // Base64URL a-zA-Z0-9-_ Base64URL = LetterNumbers + "-_" )
const BOM = "\uFEFF"
BOM "\uFEFF"
Variables ¶
This section is empty.
Functions ¶
func Capitalize ¶
Capitalize returns a copy of the string s that the start letter mapped to their Unicode upper case.
func ChecksFunc ¶ added in v1.0.21
ChecksFunc return false if s ==” or any rune with f(r) is false
func Clone ¶ added in v1.0.14
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 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.
func CompareFold ¶ added in v1.0.11
CompareFold returns an integer comparing two strings case-insensitive. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
func ContainsAny ¶
ContainsAny reports whether any Unicode code points in chars are within s.
func ContainsByte ¶
ContainsByte reports whether b is within s.
func ContainsFold ¶
ContainsFold reports whether substr is within s (case insensitive).
func ContainsFunc ¶ added in v1.0.12
ContainsFunc reports whether any Unicode code points r within s satisfy f(r).
func ContainsRune ¶
ContainsRune reports whether the Unicode code point r is within s.
func 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 CountAny ¶
CountAny counts the number of any character of chars in s. If chars is an empty string, Count returns 1 + the number of Unicode code points in s.
func CountFunc ¶ added in v1.0.23
CountFunc counts the number of character that satisfing f(c) in s.
func 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 CutAny ¶ added in v1.0.22
CutAny slices s around the first instance of any Unicode code point from chars in s, returning the text before and after separator. The found result reports whether any chars's rune appears in s. If not found, cut returns s, "", false.
func CutAt ¶ added in v1.0.14
CutAt slices s around the rune position p, returning the text before and start position p. panic if p < 0. if p == 0, return "", s. if p > RuneCount(s), return s, "".
func CutByte ¶
CutByte 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 CutFunc ¶ added in v1.0.15
CutFunc slices s around the first instance of the Unicode code point satisfying f(c), returning the text before and after f(c). The found result reports whether f(c) appears in s. If f(c) does not appear in s, cut returns s, "", false.
func CutPrefix ¶ added in v1.0.10
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 CutRune ¶
CutRune 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 CutSuffix ¶ added in v1.0.10
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 EndsWithByte ¶
EndsWithByte Tests if the byte slice bs ends with the specified suffix b.
func EndsWithFold ¶
EndsWithFold Tests if the string s ends with the specified suffix (case insensitive).
func EqualFold ¶
EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.
func 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 FieldsAny ¶
FieldsAny split string (exclude empty string) into string slice by any rune in chars
func FieldsByte ¶ added in v1.0.14
FieldsByte split string (exclude empty string) into string slice by byte c.
func FieldsFunc ¶
FieldsFunc splits the string s at each rune 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). If f does not return consistent results for a given c, FieldsFunc may crash.
func FieldsFuncIter ¶ added in v1.0.21
FieldsFuncIter splits the string s at each rune of Unicode code points c satisfying f(c) and call iter(s). stop split if iter(s) returns false.
func FieldsRune ¶
FieldsRune split string (exclude empty string) into string slice by rune r.
func HasLowerCase ¶
HasLowerCase checks if the string contains at least 1 lowercase.
func HasMultibyte ¶
HasMultibyte checks if the string contains one or more multibyte chars.
func HasPrefixFold ¶
HasPrefixFold Tests if the string s starts with the specified prefix (case insensitive).
func HasSuffixFold ¶
HasSuffixFold Tests if the string s ends with the specified suffix (case insensitive).
func HasUpperCase ¶
HasUpperCase checks if the string contains as least 1 uppercase.
func HasWhitespace ¶
HasWhitespace checks if the string contains any whitespace
func Index ¶
Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.
func 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 IndexByte ¶
IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
func IndexFold ¶
IndexFold returns the index of the first instance of substr in s (case insensitive), or -1 if substr is not present in s.
func IndexFunc ¶
IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.
func 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 IsASCIIPrintable ¶ added in v1.0.26
IsASCIIPrintable checks if the string contains printable ASCII chars only.
func IsDecimal ¶ added in v1.0.14
IsDecimal checks if the string is a decimal number "^[-+]?[0-9]+(?:\\.[0-9]+)?$".
func IsHexadecimal ¶ added in v1.0.14
IsHexadecimal checks if the string is a hexadecimal number `^(0[xX])?[0-9a-fA-F]+$`.
func IsLetterNumber ¶ added in v1.0.25
IsLetterNumber checks if the string contains only letters and numbers.
func IsUTFDigit ¶
IsUTFDigit checks if the string contains only unicode radix-10 decimal digits.
func IsUTFLetter ¶
IsUTFLetter checks if the string contains only unicode letter characters. Similar to IsLetter but for all languages.
func IsUTFLetterNumber ¶
IsUTFLetterNumber checks if the string contains only unicode letter or number characters. Similar to IsLetterNumber but for all languages.
func IsUTFNumber ¶ added in v1.0.25
IsUTFNumber checks if the string contains only unicode number characters. Similar to IsNumber but for all languages.
func IsUTFNumeric ¶
IsUTFNumeric checks if the string contains only unicode numbers of any kind. Numbers can be 0-9 but also Fractions ¾,Roman Ⅸ and Hangzhou 〩. Prefix +- are allowed.
func IsUTFPrintable ¶ added in v1.0.26
IsUTFPrintable checks if the string contains printable chars only.
func IsWhitespace ¶
IsWhitespace checks the string only contains whitespace
func 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 JoinInt64s ¶
JoinInt64s 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 JoinInts ¶
JoinInts 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 LastCut ¶
LastCut slices s around the last 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 LastCutAny ¶ added in v1.0.22
LastCutAny slices s around the last instance of any Unicode code point from chars in s, returning the text before and after separator. The found result reports whether any chars's rune appears in s. If not found, cut returns s, "", false.
func LastCutByte ¶
LastCutByte slices s around the last 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 LastCutFunc ¶ added in v1.0.15
LastCutFunc slices s around the last instance of the Unicode code point satisfying f(c), returning the text before and after f(c). The found result reports whether f(c) appears in s. If f(c) does not appear in s, cut returns s, "", false.
func LastCutRune ¶
LastCutRune slices s around the last 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 LastIndex ¶
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
func 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 LastIndexByte ¶
LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
func LastIndexFold ¶
LastIndexFold returns the index of the last instance of substr in s (case insensitive), or -1 if substr is not present in s.
func LastIndexFunc ¶
LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.
func LastIndexRune ¶
LastIndexRune returns the index of the last instance of the Unicode code point r, or -1 if rune is not present in s. If r is utf8.RuneError, it returns the last instance of any invalid UTF-8 byte sequence.
func 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 Mid ¶ added in v1.0.14
Mid slices s around the rune position p, returning the max n rune string start from the position p. panic if p < 0.
func PadCenter ¶
PadCenter Center pad a string with the string p to a new string with RuneCount(s) = size. str.PadCenter("", 4, " ") = " " str.PadCenter("ab", -1, " ") = "ab" str.PadCenter("ab", 4, " ") = " ab " str.PadCenter("abcd", 2, " ") = "abcd" str.PadCenter("a", 4, " ") = " a " str.PadCenter("a", 4, "yz") = "yayz" str.PadCenter("abc", 7, "") = "abc"
func PadCenterByte ¶
PadCenterByte Center pad a string with the byte b to a new string with len(s) = size. str.PadCenterByte("", 4, ' ') = " " str.PadCenterByte("ab", -1, ' ') = "ab" str.PadCenterByte("ab", 4, ' ') = " ab " str.PadCenterByte("abcd", 2, ' ') = "abcd" str.PadCenterByte("a", 4, ' ') = " a " str.PadCenterByte("a", 4, 'y') = "yayy"
func PadCenterRune ¶
PadCenterRune Center pad a string with the rune r to a new string with RuneCount(s) = size. str.PadCenterRune("", 4, ' ') = " " str.PadCenterRune("ab", -1, ' ') = "ab" str.PadCenterRune("ab", 4, ' ') = " ab " str.PadCenterRune("abcd", 2, ' ') = "abcd" str.PadCenterRune("a", 4, ' ') = " a " str.PadCenterRune("a", 4, 'y') = "yayy"
func PadLeft ¶
PadLeft left pad the string s with the string p to a new string with RuneCount(s) = size. str.PadLeft("", 3, "z") = "zzz" str.PadLeft("bat", 3, "yz") = "bat" str.PadLeft("bat", 5, "yz") = "yzbat" str.PadLeft("bat", 8, "yz") = "yzyzybat" str.PadLeft("bat", 1, "yz") = "bat" str.PadLeft("bat", -1, "yz") = "bat" str.PadLeft("bat", 5, "") = "bat"
func PadLeftByte ¶
PadLeftByte left pad the string s with the byte b to a new string with len(s) = size. str.PadLeftByte("", 3, 'z') = "zzz" str.PadLeftByte("bat", 3, 'z') = "bat" str.PadLeftByte("bat", 5, 'z') = "zzbat" str.PadLeftByte("bat", 1, 'z') = "bat" str.PadLeftByte("bat", -1, 'z') = "bat"
func PadLeftRune ¶
PadLeftRune left pad the string s with the rune r to a new string with RuneCount(s) = size. str.PadLeftRune("", 3, 'z') = "zzz" str.PadLeftRune("bat", 3, 'z') = "bat" str.PadLeftRune("bat", 5, 'z') = "zzbat" str.PadLeftRune("bat", 1, 'z') = "bat" str.PadLeftRune("bat", -1, 'z') = "bat"
func PadRight ¶
PadRight right pad the string s with the string p to a new string with RuneCount(s) = size. str.PadRight("", 3, "z") = "zzz" str.PadRight("bat", 3, "yz") = "bat" str.PadRight("bat", 5, "yz") = "batyz" str.PadRight("bat", 8, "yz") = "batyzyzy" str.PadRight("bat", 1, "yz") = "bat" str.PadRight("bat", -1, "yz") = "bat" str.PadRight("bat", 5, "") = "bat"
func PadRightByte ¶
PadRightByte right pad the string s with the byte b to a new string with len(s) = size. str.PadRightByte("", 3, 'z') = "zzz" str.PadRightByte("bat", 3, 'z') = "bat" str.PadRightByte("bat", 5, 'z') = "batzz" str.PadRightByte("bat", 1, 'z') = "bat" str.PadRightByte("bat", -1, 'z') = "bat"
func PadRightRune ¶
PadRightRune right pad the string s with the rune r to a new string with RuneCount(s) = size. str.PadRightRune("", 3, 'z') = "zzz" str.PadRightRune("bat", 3, 'z') = "bat" str.PadRightRune("bat", 5, 'z') = "batzz" str.PadRightRune("bat", 1, 'z') = "bat" str.PadRightRune("bat", -1, 'z') = "bat"
func PascalCase ¶
PascalCase returns a copy of the string s with pascal case.
func RandLetterNumbers ¶
RandLetterNumbers create a random letter number string
func RandLowerLetters ¶ added in v1.0.25
RandLowerLetters create a random lower letter string
func RandString ¶
RandString create a random string by the input chars if chars is omitted, the LetterNumberSymbols is used
func RandSymbols ¶ added in v1.0.25
RandSymbols create a random letter string
func RandUpperLetters ¶ added in v1.0.25
RandUpperLetters create a random upper letter string
func RemoveByte ¶
RemoveByte Removes all occurrences of the byte b from the source string s.
func RemoveEmpties ¶ added in v1.0.13
RemoveEmpties remove empty string in the string array 'ss', and returns the string array 'ss'
func RemoveFunc ¶ added in v1.0.10
RemoveFunc Removes all occurrences of characters from within the source string which satisfy f(c).
func RemoveRune ¶ added in v1.0.11
RemoveRune Removes all occurrences of the rune r from the source string s.
func Removes ¶ added in v1.0.12
Removes remove string 'v' in the string array 'ss', and returns the string array 'ss'
func 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 RepeatByte ¶
RepeatByte returns a new string consisting of count copies of the byte b.
It panics if count is negative or if
func RepeatRune ¶
RepeatRune returns a new string consisting of count copies of the rune r.
It panics if count is negative or if the result of (utf8.RuneLen(r) * count) overflows.
func 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 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 ReplaceFunc ¶ added in v1.0.21
ReplaceFunc replace all runes with function `f`
func RuneEqualFold ¶
RuneEqualFold reports whether sr and tr, are equal under Unicode case-folding, which is a more general form of case-insensitivity.
func SkipBOM ¶ added in v1.0.12
SkipBOM Returns a string without BOM. internal call TrimPrefix(s, "\uFEFF")
func SnakeCaseWithRune ¶ added in v1.0.18
SnakeCaseWithRune returns a copy of the string s with snake case rune d.
func 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.
func 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 SplitAfterN ¶
SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for SplitAfter.
func SplitCount ¶ added in v1.0.12
SplitCount splits the string s by the length 'n' to a string slice. Each string 's' in the result slice satisfying utf8.RuneCountInString(s) <= n.
func SplitFunc ¶
SplitFunc splits the string s at each rune of Unicode code points c satisfying f(c) and returns an array of slices of s. If s does not satisfying f(c), Split returns a slice of length 1 whose only element is s.
func SplitLength ¶ added in v1.0.12
SplitLength splits the string s by the length 'n' to a string slice. Each string 's' in the result slice satisfying len(s) <= n.
func SplitN ¶
SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for Split.
func StartsWith ¶
StartsWith Tests if the string s starts with the specified prefix.
func StartsWithByte ¶
StartsWithByte Tests if the byte slice s starts with the specified prefix b.
func StartsWithFold ¶
StartsWithFold Tests if the string s starts with the specified prefix (case insensitive).
func Strip ¶
Strip returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
func StripLeft ¶
StripLeft returns a slice of the string s, with all leading white space removed, as defined by Unicode.
func StripLefts ¶ added in v1.0.9
StripLefts left strip all string in the string array ss.
func StripRight ¶
StripRight returns a slice of the string s, with all trailing white space removed, as defined by Unicode.
func StripRights ¶ added in v1.0.9
StripRights right strip all string in the string array ss.
func SubstrAfter ¶
SubstrAfter Gets the substring after the first occurrence of a separator b. The separator b is not returned. If nothing is found, the empty string is returned. SubstrAfter("", *) = "" SubstrAfter("abc", "a") = "bc" SubstrAfter("abcba", "b") = "cba" SubstrAfter("abc", "c") = "" SubstrAfter("abc", "d") = ""
func SubstrAfterAny ¶ added in v1.0.10
SubstrAfterAny Gets the substring after the first occurrence of any char in separator b. The separator b is not returned. If nothing is found, the empty string is returned. SubstrAfterAny("", *) = "" SubstrAfterAny("abc", "az") = "bc" SubstrAfterAny("abcba", "b") = "cba" SubstrAfterAny("abc", "c") = "" SubstrAfterAny("abc", "d") = ""
func SubstrAfterByte ¶
SubstrAfterByte Gets the substring after the first occurrence of a separator b. The separator b is not returned. If nothing is found, the empty string is returned. SubstrAfterByte("", *) = "" SubstrAfterByte("abc", 'a') = "bc" SubstrAfterByte("abcba", 'b') = "cba" SubstrAfterByte("abc", 'c') = "" SubstrAfterByte("abc", 'd') = ""
func SubstrAfterLast ¶
SubstrAfterLast Gets the substring after the last occurrence of a separator b. The separator b is not returned. If nothing is found, the empty string is returned.
SubstrAfterLast("", *) = "" SubstrAfterLast("abc", "a") = "bc" SubstrAfterLast("abcba", "b") = "a" SubstrAfterLast("abc", "c") = "" SubstrAfterLast("a", "a") = "" SubstrAfterLast("a", "z") = ""
func SubstrAfterLastAny ¶ added in v1.0.10
SubstrAfterLastAny Gets the substring after the last occurrence of any char in separator b. The separator b is not returned. If nothing is found, the empty string is returned.
SubstrAfterLastAny("", *) = "" SubstrAfterLastAny("abc", "az") = "bc" SubstrAfterLastAny("abcba", "b") = "a" SubstrAfterLastAny("abc", "c") = "" SubstrAfterLastAny("a", "a") = "" SubstrAfterLastAny("a", "z") = ""
func SubstrAfterLastByte ¶
SubstrAfterLastByte Gets the substring after the last occurrence of a separator b. The separator b is not returned. If nothing is found, the empty string is returned.
SubstrAfterLastByte("", *) = "" SubstrAfterLastByte("abc", 'a') = "bc" SubstrAfterLastByte("abcba", 'b') = "a" SubstrAfterLastByte("abc", 'c') = "" SubstrAfterLastByte("a", 'a') = "" SubstrAfterLastByte("a", 'z') = ""
func SubstrAfterLastRune ¶
SubstrAfterLastRune Gets the substring after the last occurrence of a separator r. The separator r is not returned. If nothing is found, the empty string is returned.
SubstrAfterLastRune("", *) = "" SubstrAfterLastRune("abc", 'a') = "bc" SubstrAfterLastRune("abcba", 'b') = "a" SubstrAfterLastRune("abc", 'c') = "" SubstrAfterLastRune("a", 'a') = "" SubstrAfterLastRune("a", 'z') = ""
func SubstrAfterRune ¶
SubstrAfterRune Gets the substring after the first occurrence of a separator r. The separator r is not returned. If nothing is found, the empty string is returned. SubstrAfterRune("", *) = "" SubstrAfterRune("abc", 'a') = "bc" SubstrAfterRune("abcba", 'b') = "cba" SubstrAfterRune("abc", 'c') = "" SubstrAfterRune("abc", 'd') = ""
func SubstrBefore ¶
SubstrBefore Gets the substring before the first occurrence of a separator b. The separator b is not returned. If nothing is found, the input string is returned. SubstrBefore("", *) = "" SubstrBefore("abc", "a") = "" SubstrBefore("abcba", "b") = "a" SubstrBefore("abc", "c") = "ab" SubstrBefore("abc", "d") = "abc"
func SubstrBeforeAny ¶ added in v1.0.10
SubstrBeforeAny Gets the substring before the first occurrence of any chat in separator b. The separator b is not returned. If nothing is found, the input string is returned. SubstrBeforeAny("", *) = "" SubstrBeforeAny("abc", "a") = "" SubstrBeforeAny("abcba", "cb") = "a" SubstrBeforeAny("abc", "zc") = "ab" SubstrBeforeAny("abc", "d") = "abc"
func SubstrBeforeByte ¶
SubstrBeforeByte Gets the substring before the first occurrence of a separator b. The separator b is not returned. If nothing is found, the input string is returned. SubstrBeforeByte("", *) = "" SubstrBeforeByte("abc", 'a') = "" SubstrBeforeByte("abcba", 'b') = "a" SubstrBeforeByte("abc", 'c') = "ab" SubstrBeforeByte("abc", 'd') = "abc"
func SubstrBeforeLast ¶
SubstrBeforeLast Gets the substring before the last occurrence of a separator b. The separator b is not returned. If nothing is found, the input string is returned.
SubstrBeforeLast("", *) = "" SubstrBeforeLast("abc", "a") = "" SubstrBeforeLast("abcba", "b") = "a" SubstrBeforeLast("abc", "c") = "ab" SubstrBeforeLast("a", "a") = "" SubstrBeforeLast("a", "z") = "a" SubstrBeforeLast("a", "") = "a"
func SubstrBeforeLastAny ¶ added in v1.0.10
SubstrBeforeLastAny Gets the substring before the last occurrence of any char in separator b. The separator b is not returned. If nothing is found, the input string is returned.
SubstrBeforeLastAny("", *) = "" SubstrBeforeLastAny("abc", "a") = "" SubstrBeforeLastAny("abcba", "bc") = "a" SubstrBeforeLastAny("abc", "zc") = "ab" SubstrBeforeLastAny("a", "a") = "" SubstrBeforeLastAny("a", "z") = "a" SubstrBeforeLastAny("a", "") = "a"
func SubstrBeforeLastByte ¶
SubstrBeforeLastByte Gets the substring before the last occurrence of a separator b. The separator b is not returned. If nothing is found, the input string is returned.
SubstrBeforeLastByte("", *) = "" SubstrBeforeLastByte("abc", 'a') = "" SubstrBeforeLastByte("abcba", 'b') = "abc" SubstrBeforeLastByte("abc", 'c') = "ab" SubstrBeforeLastByte("a", 'a') = "" SubstrBeforeLastByte("a", 'z') = "a"
func SubstrBeforeLastRune ¶
SubstrBeforeLastRune Gets the substring before the last occurrence of a separator r. The separator r is not returned. If nothing is found, the input string is returned.
SubstrBeforeLastRune("", *) = "" SubstrBeforeLastRune("abc", 'a') = "" SubstrBeforeLastRune("abcba", 'b') = "abc" SubstrBeforeLastRune("abc", 'c') = "ab" SubstrBeforeLastRune("a", 'a') = "" SubstrBeforeLastRune("a", 'z') = "a"
func SubstrBeforeRune ¶
SubstrBeforeRune Gets the substring before the first occurrence of a separator r. The separator r is not returned. If nothing is found, the input string is returned. SubstrBeforeRune("", *) = "" SubstrBeforeRune("abc", 'a') = "" SubstrBeforeRune("abcba", 'b') = "a" SubstrBeforeRune("abc", 'c') = "ab" SubstrBeforeRune("abc", 'd') = "abc"
func ToLowerSpecial ¶
func ToLowerSpecial(c unicode.SpecialCase, s string) string
ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their lower case using the case mapping specified by c.
func ToTitle ¶
ToTitle returns a copy of the string s with all Unicode letters mapped to their Unicode title case.
func ToTitleSpecial ¶
func ToTitleSpecial(c unicode.SpecialCase, s string) string
ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their Unicode title case, giving priority to the special casing rules.
func ToUpperSpecial ¶
func ToUpperSpecial(c unicode.SpecialCase, s string) string
ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their upper case using the case mapping specified by c.
func ToValidUTF8 ¶
ToValidUTF8 returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.
func ToValidUTF8s ¶ added in v1.0.23
ToValidUTF8s returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.
func Trim ¶
Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
func TrimAny ¶ added in v1.0.18
TrimAny returns a slice of the string s, with all leading and trailing cutset removed.
func TrimFunc ¶
TrimFunc returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.
func TrimLeft ¶
TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
func TrimLeftFunc ¶
TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.
func TrimPrefix ¶
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
func TrimRight ¶
TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
func TrimRightFunc ¶
TrimRightFunc returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.
func TrimSpace ¶
TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
func TrimSpaces ¶
TrimSpaces trim every string in the string array.
func TrimSuffix ¶
TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.
func UnsafeBytes ¶
UnsafeBytes returns a []byte from string with no memory allocations
func UnsafeString ¶ added in v1.0.14
UnsafeString returns a string from []byte with no memory allocations
Types ¶
type Replacer ¶
func 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.