strs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Htmlspecialchars added in v0.4.2

func Htmlspecialchars(str string) string

Htmlspecialchars converts special characters to HTML entities.

func HtmlspecialcharsDecode added in v0.4.2

func HtmlspecialcharsDecode(str string) string

HtmlspecialcharsDecode converts special HTML entities back to characters.

func InArray

func InArray(needle string, haystack []string) bool

InArray checks if a string is in a string array.

Example:

InArray("abc", []string{"abc", "def"}) // true

func Is

func Is(pattern, value string) bool

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 IsUuid added in v0.4.2

func IsUuid(str string) bool

IsUuid returns true if the string is a valid UUID.

func Lcfirst added in v0.4.2

func Lcfirst(str string) string

Lcfirst returns a string with the first character in lowercase.

func Len added in v0.4.2

func Len(s string) int

Len is alias of Length.

func Length

func Length(s string) int

Length returns the length of a string. support chinese characters.

Example:

Length("abc") // 3
Length("张三李四") // 4

func Limit

func Limit(s string, length int, suffix ...string) string

Limit returns a string with a specified length. support chinese characters.

Example:

Limit("abc", 2) // "ab"
Limit("张三李四", 2) // "张三"
Limit("张三李四", 2, "...") // "张三..."

func Md5

func Md5(s string) string

Md5 returns the md5 hash of a string.

Example:

Md5("abc") // 900150983cd24fb0d6963f7d28e17f72

func RandomString

func RandomString(length int) string

RandomString returns a random string with the specified length.

Example:

RandomString(10) // "qujrlkhyqr"

func ReplaceVars added in v0.4.2

func ReplaceVars(str string, vars map[string]string) string

ReplaceVars replaces all occurrences of the search strings with the replacement strings.

func Sha1

func Sha1(s string) string

Sha1 returns the sha1 hash of a string.

Example:

Sha1("abc") // a9993e364706816aba3e25717850c26c9cd0d89d

func Shuffle

func Shuffle(s string) string

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

func Strcut(s string, start, length int) string

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

func Strpos(haystack, needle string) int

Strpos returns the position of the first occurrence of a substring in a string.

Example:

Strpos("abc", "b") // 1

func Strrev

func Strrev(s string) string

Strrev returns a string with its characters in reverse order.

Example:

Strrev("abc") // "cba"

func Strrpos

func Strrpos(haystack, needle string) int

Strrpos returns the position of the last occurrence of a substring in a string.

Example:

Strrpos("abc", "b") // 1

func Strtr

func Strtr(s, from, to string) string

Strtr replaces all occurrences of the search string with the replacement string.

Example:

Strtr("aabbcc", "a", "b") // "bbbbcc"

func Trim added in v0.4.2

func Trim(str string) string

Trim returns a string with whitespace stripped from the beginning and end of str.

func Ucfirst added in v0.4.2

func Ucfirst(str string) string

Ucfirst returns a string with the first character in uppercase.

Types

type AtoiResp added in v0.5.0

type AtoiResp struct {
	// contains filtered or unexported fields
}

AtoiResp is the result of Atoi.

func Atoi

func Atoi(s string) AtoiResp

Atoi converts a string to an int.

func (AtoiResp) Err added in v0.5.0

func (r AtoiResp) Err() error

Err returns the error of the result.

func (AtoiResp) IsErr added in v0.5.0

func (r AtoiResp) IsErr() bool

IsErr returns true if the result is an error.

func (AtoiResp) IsOk added in v0.5.0

func (r AtoiResp) IsOk() bool

IsOk returns true if the result is ok.

func (AtoiResp) Val added in v0.5.0

func (r AtoiResp) Val() int

Val returns the value of the result.

type Rune added in v0.4.2

type Rune rune

type Runes added in v0.4.2

type Runes []Rune

func (Runes) Bytes added in v0.4.2

func (r Runes) Bytes() []byte

Bytes returns the bytes of the string.

func (Runes) Cap added in v0.4.2

func (r Runes) Cap() int

Cap returns the capacity of the runes.

func (Runes) IsEmpty added in v0.4.2

func (r Runes) IsEmpty() bool

IsEmpty returns true if the runes is empty.

func (Runes) IsEqual added in v0.4.2

func (r Runes) IsEqual(s string) bool

IsEqual returns true if the runes is equal to the string.

func (Runes) IsNotEmpty added in v0.4.2

func (r Runes) IsNotEmpty() bool

IsNotEmpty returns true if the runes is not empty.

func (Runes) IsNotEqual added in v0.4.2

func (r Runes) IsNotEqual(s string) bool

IsNotEqual returns true if the runes is not equal to the string.

func (Runes) Len added in v0.4.2

func (r Runes) Len() int

Len returns the length of the runes.

func (Runes) String added in v0.4.2

func (r Runes) String() string

String returns the string of the runes.

func (Runes) Substr added in v0.4.2

func (r Runes) Substr(start, length int) string

Substr returns the substring of the runes.

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) Atoi

func (s String) Atoi() AtoiResp

Atoi returns the integer value of a string.

func (String) Bytes

func (s String) Bytes() []byte

Bytes returns the bytes of the string.

func (String) Htmlspecialchars added in v0.4.2

func (s String) Htmlspecialchars() string

Htmlspecialchars returns a string with special HTML characters encoded.

func (String) HtmlspecialcharsDecode added in v0.4.2

func (s String) HtmlspecialcharsDecode() string

HtmlspecialcharsDecode returns a string with special HTML characters decoded.

func (String) InArray

func (s String) InArray(arr []string) bool

InArray checks if a string is in a string array.

func (String) Is

func (s String) Is(pattern string) bool

Is checks if the string matches the pattern.

func (String) IsUuid added in v0.4.2

func (s String) IsUuid() bool

IsUuid returns true if the string is a valid uuid.

func (String) Lcfirst added in v0.4.2

func (s String) Lcfirst() string

Lcfirst returns a string with the first character in lowercase.

func (String) Length

func (s String) Length() int

Length returns the length of the string.

func (String) Limit

func (s String) Limit(length int, suffix ...string) string

Limit returns part of a string.

func (String) Md5

func (s String) Md5() string

Md5 returns the md5 hash of a string.

func (String) Sha1

func (s String) Sha1() string

Sha1 returns the sha1 hash of a string.

func (String) Shuffle

func (s String) Shuffle() string

Shuffle returns a string with the characters in reverse order.

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) Strcut

func (s String) Strcut(start, length int) string

Strcut returns part of a string.

func (String) String added in v0.4.2

func (s String) String() string

String returns the string value.

func (String) Strpos

func (s String) Strpos(substr string) int

Strpos returns the position of the first occurrence of a substring in a string.

func (String) Strrev

func (s String) Strrev() string

Strrev returns a string with the characters in reverse order.

func (String) Strrpos

func (s String) Strrpos(substr string) int

Strrpos returns the position of the last occurrence of a substring in a string.

func (String) Strtr

func (s String) Strtr(from, to string) string

Strtr returns a string with the characters in reverse order.

func (String) Trim added in v0.4.2

func (s String) Trim() string

Trim returns a string with whitespace stripped from the beginning and end of the string.

func (String) Ucfirst added in v0.4.2

func (s String) Ucfirst() string

Ucfirst returns a string with the first character in uppercase.

Jump to

Keyboard shortcuts

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