stringutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const Text_err_not_email = "字符串不是一个有效的邮箱"
View Source
const Text_err_not_uuid = "字符串不是一个有效的UUID"

Variables

This section is empty.

Functions

func Container added in v0.5.0

func Container(slice []string, str string) bool

func GenerateKey added in v0.5.0

func GenerateKey() (string, error)

GenerateKey 生成一个唯一的字符串key。 类似于"github.com/google/uuid", 但不具备像UUID那样的强大的唯一性保证和标准格式。

func HasSuffix

func HasSuffix(filename string) string

判断字符串是否有文件的后缀 如果没有返回空字符串

func IsDir

func IsDir(path string) (bool, error)

func IsEmail

func IsEmail(email string) error

判断字符串是否是Email

func IsFormatString

func IsFormatString(s string) bool

IsFormatString 检查字符串是否包含格式化字符串。

func IsUUID

func IsUUID(u string) error

判断字符串是否是UUID

func IsUpper

func IsUpper(s string) bool

IsUpper 函数检查字符串的第一个字符是否为大写字母。

func LengthOfLongestSubstring

func LengthOfLongestSubstring(s string) int

无重复字符的最长子串 采用滑动窗口方式时间复杂度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 MoveElementToEndAndRemovePrevious

func MoveElementToEndAndRemovePrevious[T any](arr []T, elementIndex int) ([]T, error)

func NumberToLetters added in v0.5.0

func NumberToLetters(n int) string

numberToLetters 将数字转换为字母。 例如,0 -> "A",1 -> "B",...,25 -> "Z",26 -> "AA",27 -> "AB",...。

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase 函数将字符串转换为蛇形命名法(snake_case)。 它将所有字符转换为小写,并在大写字母前添加下划线,第一个字符除外。

func ToUpperFirst

func ToUpperFirst(s string, sep string, num int) string

ToUpperFirst 函数将字符串转换为大写字母开头的字符串。

Params: - s: 字符串 - sep: 分隔符,如果为空,则不分割 - num: 需要转换的首字母大写的数量,如果为-1,则全部转换,如果为0,则不转换

Types

This section is empty.

Jump to

Keyboard shortcuts

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