str

package
v1.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 12 Imported by: 23

Documentation

Index

Constants

View Source
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 + "-_"
)
View Source
const BOM = "\uFEFF"

BOM "\uFEFF"

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

CamelCase returns a copy of the string s with camel case.

func Capitalize

func Capitalize(s string) string

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

func ChecksFunc(s string, f func(rune) bool) bool

ChecksFunc return false if s ==” or any rune with f(r) is false

func Clone added in v1.0.14

func Clone(s string) string

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

func Compare(a, b string) int

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

func CompareFold(s, t string) int

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 Contains

func Contains(s, substr string) bool

Contains reports whether substr is within s.

func ContainsAny

func ContainsAny(s, chars string) bool

ContainsAny reports whether any Unicode code points in chars are within s.

func ContainsByte

func ContainsByte(s string, b byte) bool

ContainsByte reports whether b is within s.

func ContainsFold

func ContainsFold(s, substr string) bool

ContainsFold reports whether substr is within s (case insensitive).

func ContainsFunc added in v1.0.12

func ContainsFunc(s string, f func(rune) bool) bool

ContainsFunc reports whether any Unicode code points r within s satisfy f(r).

func ContainsRune

func ContainsRune(s string, r rune) bool

ContainsRune reports whether the Unicode code point r is within s.

func Count

func Count(s, substr string) int

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

func CountAny(s, chars string) int

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 CountByte added in v1.0.12

func CountByte(s string, b byte) int

CountByte counts the number of b in s.

func CountFunc added in v1.0.23

func CountFunc(s string, f func(rune) bool) int

CountFunc counts the number of character that satisfing f(c) in s.

func CountRune

func CountRune(s string, c rune) int

CountRune counts the number of c in s.

func Cut

func Cut(s, sep string) (before, after string, found bool)

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

func CutAny(s string, chars string) (before, after string, found bool)

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

func CutAt(s string, p int) (before, after string)

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

func CutByte(s string, sep byte) (before, after string, found bool)

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

func CutFunc(s string, f func(rune) bool) (before, after string, found bool)

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

func CutPrefix(s, prefix string) (after string, found bool)

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

func CutRune(s string, sep rune) (before, after string, found bool)

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

func CutSuffix(s, suffix string) (before string, found bool)

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 EndsWith

func EndsWith(s, suffix string) bool

EndsWith Tests if the string s ends with the specified suffix.

func EndsWithByte

func EndsWithByte(s string, b byte) bool

EndsWithByte Tests if the byte slice bs ends with the specified suffix b.

func EndsWithFold

func EndsWithFold(s, suffix string) bool

EndsWithFold Tests if the string s ends with the specified suffix (case insensitive).

func EqualFold

func EqualFold(s, t string) bool

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

func Fields(s string) []string

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

func FieldsAny(s, chars string) []string

FieldsAny split string (exclude empty string) into string slice by any rune in chars

func FieldsByte added in v1.0.14

func FieldsByte(s string, c byte) []string

FieldsByte split string (exclude empty string) into string slice by byte c.

func FieldsFunc

func FieldsFunc(s string, f func(rune) bool) []string

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

func FieldsFuncIter(s string, f func(rune) bool, iter func(string) bool)

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

func FieldsRune(s string, r rune) []string

FieldsRune split string (exclude empty string) into string slice by rune r.

func HasLowerCase

func HasLowerCase(s string) bool

HasLowerCase checks if the string contains at least 1 lowercase.

func HasMultibyte

func HasMultibyte(s string) bool

HasMultibyte checks if the string contains one or more multibyte chars.

func HasPrefix

func HasPrefix(s, prefix string) bool

HasPrefix tests whether the string s begins with prefix.

func HasPrefixFold

func HasPrefixFold(s, prefix string) bool

HasPrefixFold Tests if the string s starts with the specified prefix (case insensitive).

func HasSuffix

func HasSuffix(s, suffix string) bool

HasSuffix tests whether the string s ends with suffix.

func HasSuffixFold

func HasSuffixFold(s, suffix string) bool

HasSuffixFold Tests if the string s ends with the specified suffix (case insensitive).

func HasUpperCase

func HasUpperCase(s string) bool

HasUpperCase checks if the string contains as least 1 uppercase.

func HasWhitespace

func HasWhitespace(s string) bool

HasWhitespace checks if the string contains any whitespace

func If

func If(b bool, t, f string) string

If return (b ? t : f)

func IfEmpty

func IfEmpty(a, b string) string

IfEmpty return (a == "" ? b : a)

func Index

func Index(s, substr string) int

Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.

func IndexAny

func IndexAny(s, chars string) int

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

func IndexByte(s string, c byte) int

IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.

func IndexFold

func IndexFold(s, substr string) int

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

func IndexFunc(s string, f func(rune) bool) int

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

func IndexRune

func IndexRune(s string, r rune) int

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 IsASCII

func IsASCII(s string) bool

IsASCII checks if the string contains ASCII chars only.

func IsASCIIPrintable added in v1.0.26

func IsASCIIPrintable(s string) bool

IsASCIIPrintable checks if the string contains printable ASCII chars only.

func IsDecimal added in v1.0.14

func IsDecimal(s string) bool

IsDecimal checks if the string is a decimal number "^[-+]?[0-9]+(?:\\.[0-9]+)?$".

func IsEmpty

func IsEmpty(s string) bool

IsEmpty checks if the string is null.

func IsHexadecimal added in v1.0.14

func IsHexadecimal(s string) bool

IsHexadecimal checks if the string is a hexadecimal number `^(0[xX])?[0-9a-fA-F]+$`.

func IsLetter added in v1.0.25

func IsLetter(s string) bool

IsLetter checks if the string contains only letters (a-zA-Z).

func IsLetterNumber added in v1.0.25

func IsLetterNumber(s string) bool

IsLetterNumber checks if the string contains only letters and numbers.

func IsLowerCase

func IsLowerCase(s string) bool

IsLowerCase checks if the string is lowercase.

func IsNotEmpty

func IsNotEmpty(s string) bool

IsNotEmpty checks if the string is not null.

func IsNumber

func IsNumber(s string) bool

IsNumber checks if the string contains only numbers.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks if the string contains only numbers and prefix [+-].

func IsUTFDigit

func IsUTFDigit(s string) bool

IsUTFDigit checks if the string contains only unicode radix-10 decimal digits.

func IsUTFLetter

func IsUTFLetter(s string) bool

IsUTFLetter checks if the string contains only unicode letter characters. Similar to IsLetter but for all languages.

func IsUTFLetterNumber

func IsUTFLetterNumber(s string) bool

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

func IsUTFNumber(s string) bool

IsUTFNumber checks if the string contains only unicode number characters. Similar to IsNumber but for all languages.

func IsUTFNumeric

func IsUTFNumeric(s string) bool

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

func IsUTFPrintable(s string) bool

IsUTFPrintable checks if the string contains printable chars only.

func IsUpperCase

func IsUpperCase(s string) bool

IsUpperCase checks if the string is uppercase.

func IsWhitespace

func IsWhitespace(s string) bool

IsWhitespace checks the string only contains whitespace

func Join

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

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

func JoinInt64s(elems []int64, sep string, fmt ...func(int64) string) string

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

func JoinInts(elems []int, sep string, fmt ...func(int) string) string

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

func LastCut(s, sep string) (before, after string, found bool)

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

func LastCutAny(s string, chars string) (before, after string, found bool)

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

func LastCutByte(s string, sep byte) (before, after string, found bool)

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

func LastCutFunc(s string, f func(rune) bool) (before, after string, found bool)

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

func LastCutRune(s string, sep rune) (before, after string, found bool)

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

func LastIndex(s, substr string) int

LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.

func LastIndexAny

func LastIndexAny(s, chars string) int

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

func LastIndexByte(s string, c byte) int

LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.

func LastIndexFold

func LastIndexFold(s, substr string) int

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

func LastIndexFunc(s string, f func(rune) bool) int

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

func LastIndexRune

func LastIndexRune(s string, r rune) int

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 Left added in v1.0.14

func Left(s string, n int) string

Left return the leftmost n rune string.

func Map

func Map(mapping func(rune) rune, s string) string

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

func Mid(s string, p, n int) string

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

func PadCenter(s string, size int, p string) string

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

func PadCenterByte(s string, size int, b byte) string

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

func PadCenterRune(s string, size int, c rune) string

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

func PadLeft(s string, size int, p string) string

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

func PadLeftByte(s string, size int, b byte) string

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

func PadLeftRune(s string, size int, r rune) string

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

func PadRight(s string, size int, p string) string

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

func PadRightByte(s string, size int, b byte) string

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

func PadRightRune(s string, size int, r rune) string

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

func PascalCase(s string) string

PascalCase returns a copy of the string s with pascal case.

func RandLetterNumbers

func RandLetterNumbers(size int) string

RandLetterNumbers create a random letter number string

func RandLetters

func RandLetters(size int) string

RandLetters create a random letter string

func RandLowerLetters added in v1.0.25

func RandLowerLetters(size int) string

RandLowerLetters create a random lower letter string

func RandNumbers

func RandNumbers(size int) string

RandNumbers create a random number string

func RandString

func RandString(size int, chars ...string) string

RandString create a random string by the input chars if chars is omitted, the LetterNumberSymbols is used

func RandSymbols added in v1.0.25

func RandSymbols(size int) string

RandSymbols create a random letter string

func RandUpperLetters added in v1.0.25

func RandUpperLetters(size int) string

RandUpperLetters create a random upper letter string

func Remove added in v1.0.11

func Remove(s string, r string) string

Remove Removes all substring r from within the source string s.

func RemoveAny

func RemoveAny(s string, r string) string

RemoveAny Removes all occurrences of characters from within the source string s.

func RemoveByte

func RemoveByte(s string, b byte) string

RemoveByte Removes all occurrences of the byte b from the source string s.

func RemoveEmpties added in v1.0.13

func RemoveEmpties(ss []string) []string

RemoveEmpties remove empty string in the string array 'ss', and returns the string array 'ss'

func RemoveFunc added in v1.0.10

func RemoveFunc(s string, f func(r rune) bool) string

RemoveFunc Removes all occurrences of characters from within the source string which satisfy f(c).

func RemoveRune added in v1.0.11

func RemoveRune(s string, r rune) string

RemoveRune Removes all occurrences of the rune r from the source string s.

func Removes added in v1.0.12

func Removes(ss []string, v string) []string

Removes remove string 'v' in the string array 'ss', and returns the string array 'ss'

func Repeat

func Repeat(s string, count int) string

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

func RepeatByte(b byte, count int) string

RepeatByte returns a new string consisting of count copies of the byte b.

It panics if count is negative or if

func RepeatRune

func RepeatRune(r rune, count int) string

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

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

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

func ReplaceAll(s, old, new string) string

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

func ReplaceFunc(s string, f func(rune) rune) string

ReplaceFunc replace all runes with function `f`

func Right(s string, n int) string

Right return the rightmost n rune string.

func RuneCount

func RuneCount(s string) int

RuneCount returns the number of runes in s.

func RuneEqualFold

func RuneEqualFold(sr, tr rune) bool

RuneEqualFold reports whether sr and tr, are equal under Unicode case-folding, which is a more general form of case-insensitivity.

func RuneLen

func RuneLen(r rune) int

RuneLen returns the number of runes in s.

func SkipBOM added in v1.0.12

func SkipBOM(s string) string

SkipBOM Returns a string without BOM. internal call TrimPrefix(s, "\uFEFF")

func SnakeCase

func SnakeCase(s string) string

SnakeCase returns a copy of the string s with snake case.

func SnakeCaseWithRune added in v1.0.18

func SnakeCaseWithRune(s string, d rune) string

SnakeCaseWithRune returns a copy of the string s with snake case rune d.

func Split

func Split(s, sep string) []string

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

func SplitAfter(s, sep string) []string

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

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

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 SplitAny

func SplitAny(s, chars string) []string

SplitAny split string into string slice by any rune in chars

func SplitCount added in v1.0.12

func SplitCount(s string, n int) []string

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

func SplitFunc(s string, f func(rune) bool) []string

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

func SplitLength(s string, n int) []string

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

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

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

func StartsWith(s, prefix string) bool

StartsWith Tests if the string s starts with the specified prefix.

func StartsWithByte

func StartsWithByte(s string, b byte) bool

StartsWithByte Tests if the byte slice s starts with the specified prefix b.

func StartsWithFold

func StartsWithFold(s, prefix string) bool

StartsWithFold Tests if the string s starts with the specified prefix (case insensitive).

func Strip

func Strip(s string) string

Strip returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func StripLeft

func StripLeft(s string) string

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

func StripLefts(ss []string) []string

StripLefts left strip all string in the string array ss.

func StripRight

func StripRight(s string) string

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

func StripRights(ss []string) []string

StripRights right strip all string in the string array ss.

func Strips added in v1.0.9

func Strips(ss []string) []string

Strips strip all string in the string array ss.

func SubstrAfter

func SubstrAfter(s string, b string) string

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

func SubstrAfterAny(s string, b string) string

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

func SubstrAfterByte(s string, b byte) string

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

func SubstrAfterLast(s string, b string) string

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

func SubstrAfterLastAny(s string, b string) string

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

func SubstrAfterLastByte(s string, b byte) string

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

func SubstrAfterLastRune(s string, r rune) string

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

func SubstrAfterRune(s string, r rune) string

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

func SubstrBefore(s string, b string) string

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

func SubstrBeforeAny(s string, b string) string

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

func SubstrBeforeByte(s string, b byte) string

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

func SubstrBeforeLast(s string, b string) string

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

func SubstrBeforeLastAny(s string, b string) string

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

func SubstrBeforeLastByte(s string, b byte) string

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

func SubstrBeforeLastRune(s string, r rune) string

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

func SubstrBeforeRune(s string, r rune) string

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 ToLower

func ToLower(s string) string

ToLower returns s with all Unicode letters mapped to their lower case.

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 ToLowers added in v1.0.14

func ToLowers(ss []string) []string

ToLowers lowercase all string in the string array ss.

func ToTitle

func ToTitle(s string) string

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 ToUpper

func ToUpper(s string) string

ToUpper returns s with all Unicode letters mapped to their upper case.

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 ToUppers added in v1.0.14

func ToUppers(ss []string) []string

ToUppers uppercase all string in the string array ss.

func ToValidUTF8

func ToValidUTF8(s, replacement string) string

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

func ToValidUTF8s(ss []string, replacement string) []string

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

func Trim(s string, cutset string) string

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

func TrimAny(s string, cutset string) string

TrimAny returns a slice of the string s, with all leading and trailing cutset removed.

func TrimFunc

func TrimFunc(s string, f func(rune) bool) string

TrimFunc returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.

func TrimLeft

func TrimLeft(s string, cutset string) string

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

func TrimLeftFunc(s string, f func(rune) bool) string

TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.

func TrimPrefix

func TrimPrefix(s, prefix string) string

TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.

func TrimRight

func TrimRight(s string, cutset string) string

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

func TrimRightFunc(s string, f func(rune) bool) string

TrimRightFunc returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.

func TrimSpace

func TrimSpace(s string) string

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func TrimSpaces

func TrimSpaces(ss []string) []string

TrimSpaces trim every string in the string array.

func TrimSuffix

func TrimSuffix(s, suffix string) string

TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.

func UnsafeBytes

func UnsafeBytes(s string) []byte

UnsafeBytes returns a []byte from string with no memory allocations

func UnsafeString added in v1.0.14

func UnsafeString(bs []byte) string

UnsafeString returns a string from []byte with no memory allocations

Types

type Builder

type Builder = strings.Builder

type Reader

type Reader = strings.Reader

func NewReader

func NewReader(s string) *Reader

NewReader returns a new Reader reading from s. It is similar to bytes.NewBufferString but more efficient and read-only.

type Replacer

type Replacer = strings.Replacer

func NewReplacer

func NewReplacer(oldnew ...string) *Replacer

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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