Documentation ¶
Index ¶
- Constants
- func Container(slice []string, str string) bool
- func GenerateKey() (string, error)
- func HasSuffix(filename string) string
- func IsDir(path string) (bool, error)
- func IsEmail(email string) error
- func IsFormatString(s string) bool
- func IsUUID(u string) error
- func IsUpper(s string) bool
- func LengthOfLongestSubstring(s string) int
- func MoveElementToEndAndRemovePrevious[T any](arr []T, elementIndex int) ([]T, error)
- func NumberToLetters(n int) string
- func ToSnakeCase(str string) string
- func ToUpperFirst(s string, sep string, num int) string
Constants ¶
View Source
const Text_err_not_email = "字符串不是一个有效的邮箱"
View Source
const Text_err_not_uuid = "字符串不是一个有效的UUID"
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶ added in v0.5.0
GenerateKey 生成一个唯一的字符串key。 类似于"github.com/google/uuid", 但不具备像UUID那样的强大的唯一性保证和标准格式。
func LengthOfLongestSubstring ¶
无重复字符的最长子串 采用滑动窗口方式时间复杂度O(n),如果暴力解法时间复杂度为O(n^2) 这里想象一个会伸缩的窗口在字符串中,然后一个个移动过去, 如果窗口中有重复的字符,就把窗口的左边界移动到重复字符的下一个位置 否则窗口右边界向右移动一格 这段代码增加了对UTF-8字符的支持, 源代码如下,只支持ASCII字符,但是效率更高 start := 0 end := 0
for i, v := range s { index := strings.Index(string(s[start:i]), string(v)) if index == -1 { if i+1 > end { end = i + 1 } } else { start += index + 1 end += index + 1 } }
return end - start
参数: - s: 字符串
func NumberToLetters ¶ added in v0.5.0
numberToLetters 将数字转换为字母。 例如,0 -> "A",1 -> "B",...,25 -> "Z",26 -> "AA",27 -> "AB",...。
func ToSnakeCase ¶
ToSnakeCase 函数将字符串转换为蛇形命名法(snake_case)。 它将所有字符转换为小写,并在大写字母前添加下划线,第一个字符除外。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.