Documentation
¶
Index ¶
- func Htmlspecialchars(str string) string
- func HtmlspecialcharsDecode(str string) string
- func InArray(needle string, haystack []string) bool
- func Is(pattern, value string) bool
- func IsUuid(str string) bool
- func Lcfirst(str string) string
- func Len(s string) int
- func Length(s string) int
- func Limit(s string, length int, suffix ...string) string
- func Md5(s string) string
- func RandomString(length int) string
- func ReplaceVars(str string, vars map[string]string) string
- func Sha1(s string) string
- func Shuffle(s string) string
- func StrPad(s string, length int, pad string, padType StrPadType) string
- func Strcut(s string, start, length int) string
- func Strpos(haystack, needle string) int
- func Strrev(s string) string
- func Strrpos(haystack, needle string) int
- func Strtr(s, from, to string) string
- func Trim(str string) string
- func Ucfirst(str string) string
- type AtoiResp
- type Rune
- type Runes
- func (r Runes) Bytes() []byte
- func (r Runes) Cap() int
- func (r Runes) IsEmpty() bool
- func (r Runes) IsEqual(s string) bool
- func (r Runes) IsNotEmpty() bool
- func (r Runes) IsNotEqual(s string) bool
- func (r Runes) Len() int
- func (r Runes) String() string
- func (r Runes) Substr(start, length int) string
- type StrPadType
- type String
- func (s String) Atoi() AtoiResp
- func (s String) Bytes() []byte
- func (s String) Htmlspecialchars() string
- func (s String) HtmlspecialcharsDecode() string
- func (s String) InArray(arr []string) bool
- func (s String) Is(pattern string) bool
- func (s String) IsUuid() bool
- func (s String) Lcfirst() string
- func (s String) Length() int
- func (s String) Limit(length int, suffix ...string) string
- func (s String) Md5() string
- func (s String) Sha1() string
- func (s String) Shuffle() string
- func (s String) StrPad(length int, pad string, padType StrPadType) string
- func (s String) Strcut(start, length int) string
- func (s String) String() string
- func (s String) Strpos(substr string) int
- func (s String) Strrev() string
- func (s String) Strrpos(substr string) int
- func (s String) Strtr(from, to string) string
- func (s String) Trim() string
- func (s String) Ucfirst() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Htmlspecialchars ¶ added in v0.4.2
Htmlspecialchars converts special characters to HTML entities.
func HtmlspecialcharsDecode ¶ added in v0.4.2
HtmlspecialcharsDecode converts special HTML entities back to characters.
func InArray ¶
InArray checks if a string is in a string array.
Example:
InArray("abc", []string{"abc", "def"}) // true
func Is ¶
Is returns true if the value matches the pattern. The pattern can contain the wildcard character *.
Example:
Is("*.example.com", "www.example.com") // true Is("*.example.com", "example.com") // false
func Length ¶
Length returns the length of a string. support chinese characters.
Example:
Length("abc") // 3 Length("张三李四") // 4
func Limit ¶
Limit returns a string with a specified length. support chinese characters.
Example:
Limit("abc", 2) // "ab" Limit("张三李四", 2) // "张三" Limit("张三李四", 2, "...") // "张三..."
func Md5 ¶
Md5 returns the md5 hash of a string.
Example:
Md5("abc") // 900150983cd24fb0d6963f7d28e17f72
func RandomString ¶
RandomString returns a random string with the specified length.
Example:
RandomString(10) // "qujrlkhyqr"
func ReplaceVars ¶ added in v0.4.2
ReplaceVars replaces all occurrences of the search strings with the replacement strings.
func Sha1 ¶
Sha1 returns the sha1 hash of a string.
Example:
Sha1("abc") // a9993e364706816aba3e25717850c26c9cd0d89d
func Shuffle ¶
Shuffle returns a string with its characters in random order.
Example:
Shuffle("abc") // "bca"
func StrPad ¶
func StrPad(s string, length int, pad string, padType StrPadType) string
StrPad returns an input string padded on the left or right to specified length with pad string.
Example:
StrPad("abc", 6, " ", StrPadLeft) // " abc" StrPad("abc", 6, " ", StrPadRight) // "abc " StrPad("abc", 6, " ", StrPadBoth) // " abc "
func Strcut ¶
Strcut returns a string with a specified length starting from a specified position. support chinese characters.
Example:
Strcut("abc", 1, 1) // "b" Strcut("张三李四", 1, 2) // "三李
func Strpos ¶
Strpos returns the position of the first occurrence of a substring in a string.
Example:
Strpos("abc", "b") // 1
func Strrev ¶
Strrev returns a string with its characters in reverse order.
Example:
Strrev("abc") // "cba"
func Strrpos ¶
Strrpos returns the position of the last occurrence of a substring in a string.
Example:
Strrpos("abc", "b") // 1
func Strtr ¶
Strtr replaces all occurrences of the search string with the replacement string.
Example:
Strtr("aabbcc", "a", "b") // "bbbbcc"
Types ¶
type AtoiResp ¶ added in v0.5.0
type AtoiResp struct {
// contains filtered or unexported fields
}
AtoiResp is the result of Atoi.
type Runes ¶ added in v0.4.2
type Runes []Rune
func (Runes) IsNotEmpty ¶ added in v0.4.2
IsNotEmpty returns true if the runes is not empty.
func (Runes) IsNotEqual ¶ added in v0.4.2
IsNotEqual returns true if the runes is not equal to the string.
type StrPadType ¶
type StrPadType int
StrPadType is the type of padding.
const ( StrPadLeft StrPadType = iota StrPadRight StrPadBoth )
StrPadType constants.
type String ¶
type String string
func (String) Htmlspecialchars ¶ added in v0.4.2
Htmlspecialchars returns a string with special HTML characters encoded.
func (String) HtmlspecialcharsDecode ¶ added in v0.4.2
HtmlspecialcharsDecode returns a string with special HTML characters decoded.
func (String) Lcfirst ¶ added in v0.4.2
Lcfirst returns a string with the first character in lowercase.
func (String) StrPad ¶
func (s String) StrPad(length int, pad string, padType StrPadType) string
StrPad returns a string padded to a certain length with another string.
func (String) Strpos ¶
Strpos returns the position of the first occurrence of a substring in a string.
func (String) Strrpos ¶
Strrpos returns the position of the last occurrence of a substring in a string.