strings

package
v2.27.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After added in v2.21.0

func After(subject, search string) string

After Return the remainder of a string after a given value. Support chinese characters.

Example:

After("Hello, World!", ",") //  World!
After("张三李四", "三") // 李四

func Before added in v2.21.0

func Before(subject, search string) string

Before Get the portion of a string before the first occurrence of a given value. Support chinese characters.

Example:

After("Hello, World!", ",") //  Hello
After("张三李四", "李") // 张三

func InSlice added in v2.10.0

func InSlice(slice []string, s string) bool

InSlice checks if a string is in a string slice.

Example:

InSlice([]string{"1", "2"}, "1") // 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

func IsUUID(str string) bool

IsUUID returns true if the string is a valid UUID.

func Len

func Len(s string) int

Len returns the length of a string. Support chinese characters.

Example:

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

func MD5 added in v2.13.0

func MD5(s string) string

MD5 returns the md5 hash of a string.

Example:

MD5("abc") // 900150983cd24fb0d6963f7d28e17f72

func Random

func Random(length int) string

Random returns a random string with the specified length.

Example:

Random(10) // "qujrlkhyqr"

func Replace

func Replace(s, from, to string) string

Replace replaces all occurrences of one substring with another.

Example:

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

func Reverse

func Reverse(s string) string

Reverse returns a string with its characters in reverse order.

Example:

Reverse("abc") // "cba"

func SHA1 added in v2.13.0

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 SubstrCount added in v2.21.0

func SubstrCount(haystack, needle string, offset int, length ...int) int

SubstrCount Returns the number of substring occurrences.

Example:

SubstrCount("babababbaaba", "a", 0, 10) //  5
SubstrCount("121212312", "1", 1, 5) // 2

func UUID

func UUID() string

UUID generate uuid string

Types

This section is empty.

Jump to

Keyboard shortcuts

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