Documentation ¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-11 13:08:58 * @FilePath: \go-toolbox\pkg\stringx\base.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-01 02:15:52 * @FilePath: \go-toolbox\pkg\stringx\contains.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-08-03 23:11:56 * @FilePath: \go-toolbox\pkg\stringx\format.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-08-03 16:55:01 * @FilePath: \go-toolbox\pkg\stringx\index.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-09 20:06:12 * @FilePath: \go-toolbox\pkg\stringx\regexp.go * @Description: 字符串正则表达式工具包 * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-08-03 11:02:37 * @FilePath: \go-toolbox\pkg\stringx\remove.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-07-30 17:26:07 * @FilePath: \go-toolbox\pkg\stringx\repeat.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-10-16 19:49:20 * @FilePath: \go-toolbox\pkg\stringx\replace.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-07-30 17:26:07 * @FilePath: \go-toolbox\pkg\stringx\split.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-07-30 17:26:07 * @FilePath: \go-toolbox\pkg\stringx\start_end_with.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-08-03 10:15:25 * @FilePath: \go-toolbox\pkg\stringx\sub.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-07-30 17:26:07 * @FilePath: \go-toolbox\pkg\stringx\trim.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- func AddPrefixIfNot(str string, prefix string) string
- func AddSuffixIfNot(str string, suffix string) string
- func CalculateMD5Hash(input string) string
- func CleanEmpty(str string) string
- func Coalesce(s ...string) string
- func CompareIgnoreCase(str1 string, str2 string) int
- func Contains(value string, searchStr string) bool
- func ContainsAll(str string, searchStrs []string) bool
- func ContainsAny(value string, searchStrs []string) bool
- func ContainsAnyIgnoreCase(str string, searchStrs []string) bool
- func ContainsBlank(str string) bool
- func ContainsIgnoreCase(value string, searchStr string) bool
- func ConvertCharacterStyle(input string, caseType CharacterStyle) string
- func Count(str string, searchStr string) int
- func Cut(str string, n int) []string
- func EndWith(str string, suffix string) bool
- func EndWithAny(str string, suffixes []string) bool
- func EndWithAnyIgnoreCase(str string, suffixes []string) bool
- func EndWithIgnoreCase(str string, suffix string) bool
- func Equals(str1 string, str2 string) bool
- func EqualsAny(str1 string, str2 []string) bool
- func EqualsAnyIgnoreCase(str1 string, str2 []string) bool
- func EqualsAt(value string, position int, subStr string) bool
- func EqualsIgnoreCase(str1 string, str2 string) bool
- func ExtractValue(extra string, key string, searchPrefix string) string
- func Fill(str string, char string, length int, isPre bool) string
- func FillAfter(str string, char string, length int) string
- func FillBefore(str string, char string, length int) string
- func Format(template string, params map[string]interface{}) string
- func GetContainsStr(str string, searchStrs []string) string
- func HasLocalIP(ip string) bool
- func Hide(str string, startInclude int, endExclude int) string
- func IndexOf(str string, subStr string) int
- func IndexOfByRange(str string, subStr string, start int, end int) int
- func IndexOfByRangeStart(str string, subStr string, start int) int
- func IndexOfIgnoreCase(str string, subStr string) int
- func IndexOfIgnoreCaseByRange(str string, subStr string, start int) int
- func IndexedFormat(template string, params []interface{}) string
- func InsertSpaces(str string, interval int) string
- func IsChineseCharacter(str string) (isContains bool, count int)
- func IsGlobalUnicast(ip string) bool
- func IsLinkLocal(ip net.IP) bool
- func IsTrueString(s string) bool
- func IsUniqueLocalAddress(ip net.IP) bool
- func LastIndexOf(str string, subStr string) int
- func LastIndexOfByRangeStart(str string, subStr string, start int) int
- func LastIndexOfIgnoreCase(str string, subStr string) int
- func Length(str string) int
- func MatchEnCharacterDotUnderLine(str string) bool
- func OrdinalIndexOf(str string, subStr string, ordinal int, start ...int) int
- func Pad(input string, minLength int, paddler ...*Paddler) string
- func RemoveAll(str string, strToRemove string) string
- func RemoveAllLineBreaks(str string) string
- func RemoveAny(str string, strsToRemove []string) string
- func RemovePrefix(str string, prefix string) string
- func RemovePrefixIgnoreCase(str string, prefix string) string
- func RemoveSuffix(str string, suffix string) string
- func RemoveSuffixIgnoreCase(str string, suffix string) string
- func RemoveSymbols(s string) string
- func Repeat(str string, count int) string
- func RepeatAndJoin(str string, delimiter string, count int) string
- func RepeatByLength(str string, padLen int) string
- func Replace(source string, searchStr string, replacement string, replaceCount int) string
- func ReplaceAll(source string, searchStr string, replacement string) string
- func ReplaceAllIgnoreCase(source string, searchStr string, replacement string) string
- func ReplaceIgnoreCase(source string, searchStr string, replacement string, replaceCount int) string
- func ReplaceSpecialChars(str string, replaceValue rune) string
- func ReplaceWithIndex(str string, startIndex int, endIndex int, replacedStr string) string
- func ReplaceWithMatcher(str string, regex string, replaceFun func(string) string) string
- func Reverse(str string) string
- func SafeIndexOfByRange(str string, subStr string, options ...func(*searchOptions)) (index int)
- func SetPadPosition(p *Paddler, position PadPosition)
- func Split(str string, separator string) []string
- func SplitAfterMapping[T any](str string, separator string, mapping func(s string) (T, error)) []T
- func SplitByLen(str string, length int) []string
- func SplitLimit(str string, separator string, limit int) []string
- func SplitTrim(str string, separator string) []string
- func SplitTrimLimit(str string, separator string, limit int) []string
- func StartWith(str string, prefix string) bool
- func StartWithAny(str string, prefixes []string) bool
- func StartWithAnyIgnoreCase(str string, prefixes []string) bool
- func StartWithIgnoreCase(str string, prefix string) bool
- func SubAfter(str string, separator string, isLastSeparator bool) string
- func SubBefore(str string, separator string, isLastSeparator bool) string
- func SubBetween(str string, before string, after string) string
- func SubBetweenAll(str string, prefix string, suffix string) []string
- func Trim(str string) string
- func TrimEnd(str string) string
- func TrimStart(str string) string
- func Truncate(str string, maxBytes int) string
- func TruncateAppendEllipsis(str string, maxBytes int) string
- func WithEnd(end int) func(*searchOptions)
- func WithStart(start int) func(*searchOptions)
- type AnyRegs
- func (g *AnyRegs) IsHex(input string) bool
- func (g *AnyRegs) MatchChineseIDCardNumber(id string) bool
- func (g *AnyRegs) MatchChinesePhoneNumber(str string) bool
- func (g *AnyRegs) MatchContainChineseCharacter(str string) bool
- func (g *AnyRegs) MatchDoubleByte(input string) bool
- func (g *AnyRegs) MatchEmail(str string) bool
- func (g *AnyRegs) MatchEmptyLine(input string) bool
- func (g *AnyRegs) MatchEnCharacter(str string) bool
- func (g *AnyRegs) MatchGeNNumber(str string, n int) bool
- func (g *AnyRegs) MatchIPv4(input string) bool
- func (g *AnyRegs) MatchIPv6(input string) bool
- func (g *AnyRegs) MatchIntOrFloat(str string) bool
- func (g *AnyRegs) MatchIsContainSpecialCharacter(str string) bool
- func (g *AnyRegs) MatchLenNNumber(str string, n int) bool
- func (g *AnyRegs) MatchLowerEnCharacter(str string) bool
- func (g *AnyRegs) MatchMNIntervalNumber(str string, m, n int) bool
- func (g *AnyRegs) MatchMNNovelsOfRealNumber(str string, m, n int) bool
- func (g *AnyRegs) MatchNLeCharacter(str string, n int) bool
- func (g *AnyRegs) MatchNNovelsOfRealNumber(str string, n int) bool
- func (g *AnyRegs) MatchNanZeroNegNumber(str string) bool
- func (g *AnyRegs) MatchNanZeroNumber(str string) bool
- func (g *AnyRegs) MatchNumber(str string) bool
- func (g *AnyRegs) MatchNumberEnCharacter(str string) bool
- func (g *AnyRegs) MatchNumberEnUnderscores(str string) bool
- func (g *AnyRegs) MatchPass1(str string, m, n int) bool
- func (g *AnyRegs) MatchPass2(str string) bool
- func (g *AnyRegs) MatchStartingWithNonZero(str string) bool
- func (g *AnyRegs) MatchTime(input string) bool
- func (g *AnyRegs) MatchUpEnCharacter(str string) bool
- type CharacterStyle
- type PadPosition
- type Paddler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPrefixIfNot ¶
AddPrefixIfNot 如果给定字符串不是以prefix开头的,在开头补充 prefix
func AddSuffixIfNot ¶
AddSuffixIfNot 如果给定字符串不是以suffix结尾的,在尾部补充 suffix
func CalculateMD5Hash ¶
CalculateMD5Hash 计算string md5 hash值
func ContainsAll ¶
ContainsAll 检查指定字符串中是否含给定的所有字符串
func ContainsAny ¶
ContainsAny 查找指定字符串是否包含指定字符串列表中的任意一个字符串
func ContainsAnyIgnoreCase ¶
ContainsAnyIgnoreCase 找指定字符串是否包含指定字符串列表中的任意一个字符串(忽略大小写)
func ContainsBlank ¶
ContainsBlank 给定字符串是否包含空白符(空白符包括空格、制表符、全角空格和不间断空格)
func ContainsIgnoreCase ¶
ContainsIgnoreCase 指定字符是否在字符串中出现过(忽略大小写)
func ConvertCharacterStyle ¶ added in v0.11.6
func ConvertCharacterStyle(input string, caseType CharacterStyle) string
ConvertCharacterStyle 根据指定的 CharacterStyle 将字符串转换为相应的格式
func EndWithAny ¶
EndWithAny 给定字符串是否以任何一个字符串结尾 给定字符串和数组为空都返回false
func EndWithAnyIgnoreCase ¶
EndWithAnyIgnoreCase 给定字符串是否以任何一个字符串结尾(忽略大小写) 给定字符串和数组为空都返回false
func EndWithIgnoreCase ¶
EndWithIgnoreCase 是否以指定字符串结尾,忽略大小写
func EqualsAnyIgnoreCase ¶
EqualsAnyIgnoreCase 给定字符串是否与提供的中任一字符串相同(忽略大小写),相同则返回true,没有相同的返回false; 如果参与比对的字符串列表为空,返回false
func EqualsIgnoreCase ¶
EqualsIgnoreCase 比较2个字符串(大小写不敏感)
func ExtractValue ¶
ExtractValue 从给定的字符串中提取指定的键的值
func FillBefore ¶
FillBefore 将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串
func Format ¶
Format 通过map中的参数 格式化字符串 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) ---=》 aValue and bValue
func GetContainsStr ¶
GetContainsStr 查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串 不存在返回空串
func IndexOfByRange ¶
IndexOfByRange 指定范围内查找指定字符
func IndexOfByRangeStart ¶
IndexOfByRangeStart 指定范围内查找指定字符
func IndexOfIgnoreCase ¶
IndexOfIgnoreCase 返回字符在原始字符串的下标(大小写不敏感)
func IndexOfIgnoreCaseByRange ¶
IndexOfIgnoreCaseByRange 从指定下标开始,返回在字符串中的下标 (大小不敏感)
func IndexedFormat ¶
IndexedFormat 有序的格式化文本,使用{number}做为占位符 通常使用:format("this is {0} for {1}", "a", "b") =》 this is a for b
func InsertSpaces ¶
InsertSpaces 插入空值 InsertSpaces 插入空值
func IsChineseCharacter ¶ added in v0.11.5
IsChineseCharacter 检查字符串是否为纯汉字
func IsGlobalUnicast ¶ added in v0.11.5
IsGlobalUnicast 检查给定的 IP 地址是否是全球单播地址
func IsUniqueLocalAddress ¶ added in v0.11.5
IsUniqueLocalAddress 检查给定的 IP 是否为唯一本地地址(ULA)
func LastIndexOfByRangeStart ¶
LastIndexOfByRangeStart 从指定下标开始,返回最后出现指定字符串的下标
func LastIndexOfIgnoreCase ¶
LastIndexOfIgnoreCase 返回最后出现指定字符串的下标(大小写不敏感)
func MatchEnCharacterDotUnderLine ¶ added in v0.11.5
MatchEnCharacterDotUnderLine 检查字符串是否只包含字母、数字、点号和下划线
func OrdinalIndexOf ¶
OrdinalIndexOf 返回字符串 subStr 在字符串 str 中第 ordinal 次出现的位置。 如果 str="" 或 subStr=" 或 ordinal≥0 则返回-1
func RemoveAllLineBreaks ¶
RemoveAllLineBreaks 去除所有换行符,包括:\r \n
func RemovePrefixIgnoreCase ¶
RemovePrefixIgnoreCase 忽略大小写去掉指定前缀
func RemoveSuffixIgnoreCase ¶
RemoveSuffixIgnoreCase 去掉指定后缀(忽略大小写)
func RemoveSymbols ¶ added in v0.11.5
RemoveSymbols 使用正则表达式去掉字符串中的所有符号
func RepeatAndJoin ¶
RepeatAndJoin 重复某个字符串并通过分界符连接
func RepeatByLength ¶
RepeatByLength 重复某个字符串到指定长度
func ReplaceAll ¶
ReplaceAll 替换字符串
func ReplaceAllIgnoreCase ¶
ReplaceAllIgnoreCase 替换字符串
func ReplaceIgnoreCase ¶
func ReplaceIgnoreCase(source string, searchStr string, replacement string, replaceCount int) string
ReplaceIgnoreCase 替换字符串
func ReplaceSpecialChars ¶
ReplaceSpecialChars 去掉特殊符号、转为自定义
func ReplaceWithIndex ¶
ReplaceWithIndex 按照指定区间替换字符串 startIndex 开始位置(包含) endIndex 结束位置(不包含)
func ReplaceWithMatcher ¶
ReplaceWithMatcher 通过正则表达式替换字符串
func SafeIndexOfByRange ¶
SafeIndexOfByRange 在指定范围内查找指定字符,避免下标溢出
func SetPadPosition ¶
func SetPadPosition(p *Paddler, position PadPosition)
func SplitAfterMapping ¶
SplitAfterMapping 切分字符串,切分之后通过mapping转换并返回
func SplitLimit ¶
SplitLimit 分割字符串,限制分片数
func SplitTrimLimit ¶
SplitTrimLimit 切分字符串,去除切分后每个元素两边的空白符,去除空白项,限制分片数
func StartWithAny ¶
StartWithAny 给定字符串是否以任何一个字符串开始; 给定字符串和数组为空都返回false
func StartWithAnyIgnoreCase ¶
StartWithAnyIgnoreCase 给定字符串是否以任何一个字符串开始(忽略大小写) 给定字符串和数组为空都返回false
func StartWithIgnoreCase ¶
StartWithIgnoreCase 字符串是否以给定字符开始-忽略大小写
func SubBefore ¶
SubBefore 截取分隔字符串之前的字符串,不包括分隔字符串 isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个
func SubBetween ¶
SubBetween 截取指定字符串中间部分,不包括标识字符串
func SubBetweenAll ¶
SubBetweenAll 截取指定字符串多段中间部分,不包括标识字符串
func TruncateAppendEllipsis ¶
TruncateAppendEllipsis 截断字符串,使用不超过maxBytes长度。截断后自动追加省略号(...) 用于存储数据库varchar且编码为UTF-8的字段
Types ¶
type AnyRegs ¶ added in v0.11.5
type AnyRegs struct {
// contains filtered or unexported fields
}
AnyRegs 包含各种正则表达式的结构体
func NewAnyRegs ¶ added in v0.11.5
func NewAnyRegs() *AnyRegs
NewAnyRegs 创建一个新的 AnyRegs 实例,并编译所有正则表达式
func (*AnyRegs) MatchChineseIDCardNumber ¶ added in v0.11.5
MatchChineseIDCardNumber 检查字符串是否为有效的大陆身份证号
func (*AnyRegs) MatchChinesePhoneNumber ¶ added in v0.11.5
MatchChinesePhoneNumber 检查字符串是否为有效的大陆手机号
func (*AnyRegs) MatchContainChineseCharacter ¶ added in v0.11.5
MatchContainChineseCharacter 检查字符串是否包含中文字符
func (*AnyRegs) MatchDoubleByte ¶ added in v0.11.5
MatchDoubleByte 检查字符串是否包含双字节字符(包括汉字)
func (*AnyRegs) MatchEmail ¶ added in v0.11.5
MatchEmail 检查字符串是否为有效的email
func (*AnyRegs) MatchEmptyLine ¶ added in v0.11.5
MatchEmptyLine 检查字符串是否为空行
func (*AnyRegs) MatchEnCharacter ¶ added in v0.11.5
MatchEnCharacter 检查字符串是否为纯英文字符串(大小写不敏感)
func (*AnyRegs) MatchGeNNumber ¶ added in v0.11.5
MatchGeNNumber 检查字符串是否为长度不小于n的纯数字
func (*AnyRegs) MatchIntOrFloat ¶ added in v0.11.5
MatchIntOrFloat 检查字符串是否为整数或小数
func (*AnyRegs) MatchIsContainSpecialCharacter ¶ added in v0.11.5
MatchIsContainSpecialCharacter 检查字符串是否包含特殊字符
func (*AnyRegs) MatchLenNNumber ¶ added in v0.11.5
MatchLenNNumber 检查字符串是否为长度为n的纯数字
func (*AnyRegs) MatchLowerEnCharacter ¶ added in v0.11.5
MatchLowerEnCharacter 检查字符串是否为纯小写英文字符串
func (*AnyRegs) MatchMNIntervalNumber ¶ added in v0.11.5
MatchMNIntervalNumber 检查字符串是否为长度在m到n之间的纯数字
func (*AnyRegs) MatchMNNovelsOfRealNumber ¶ added in v0.11.5
MatchMNNovelsOfRealNumber 检查字符串是否为m到n位小数的正实数
func (*AnyRegs) MatchNLeCharacter ¶ added in v0.11.5
MatchNLeCharacter 检查字符串是否为长度为n的字符
func (*AnyRegs) MatchNNovelsOfRealNumber ¶ added in v0.11.5
MatchNNovelsOfRealNumber 检查字符串是否为有n位小数的正实数
func (*AnyRegs) MatchNanZeroNegNumber ¶ added in v0.11.5
MatchNanZeroNegNumber 检查字符串是否为非零的负整数
func (*AnyRegs) MatchNanZeroNumber ¶ added in v0.11.5
MatchNanZeroNumber 检查字符串是否为非零的正整数
func (*AnyRegs) MatchNumber ¶ added in v0.11.5
MatchNumber 检查字符串是否为纯数字
func (*AnyRegs) MatchNumberEnCharacter ¶ added in v0.11.5
MatchNumberEnCharacter 检查字符串是否由数字和26个英文字母组成(大小写不敏感)
func (*AnyRegs) MatchNumberEnUnderscores ¶ added in v0.11.5
MatchNumberEnUnderscores 检查字符串是否由数字和26个英文字母或下划线组成(大小写不敏感)
func (*AnyRegs) MatchPass1 ¶ added in v0.11.5
MatchPass1 检查密码1是否符合规则:由数字、26个英文字母或下划线组成的英文开头的字符串,长度在m到n位之间
func (*AnyRegs) MatchPass2 ¶ added in v0.11.5
MatchPass2 检查密码2是否符合规则: 密码长度至少为8个字符。 包含至少一个小写字母。 包含至少一个大写字母。 包含至少一个数字。 包含至少一个特殊字符(例如 !@#$%^&*() 等)
func (*AnyRegs) MatchStartingWithNonZero ¶ added in v0.11.5
MatchStartingWithNonZero 检查字符串是否为非零开头的纯数字
func (*AnyRegs) MatchUpEnCharacter ¶ added in v0.11.5
MatchUpEnCharacter 检查字符串是否为纯大写英文字符串
type CharacterStyle ¶ added in v0.11.6
type CharacterStyle int
const ( SnakeCharacterStyle CharacterStyle = iota // 表示蛇形命名法(例如:hello_world) StudlyCharacterStyle // 表示每个单词首字母大写的风格(例如:HelloWorld) CamelCharacterStyle // 表示驼峰命名法(例如:helloWorld) )
type Paddler ¶
type Paddler struct {
Position PadPosition
}