Documentation ¶
Overview ¶
Package gstr 提供字符串处理的工具函数
Index ¶
- Constants
- func ChunkSplit(body string, chunkLen int, end string) string
- func ClearWordRankCache()
- func Contains(str, substr string) bool
- func Explode(delimiter, str string) []string
- func ExtractRegexMatch(regex, content string, index int) (string, error)
- func Fields(str string) []string
- func FirstToLower(str string) string
- func FirstToUpper(str string) string
- func GetRootDomain(url string) string
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func HumpName(name string) string
- func Implode(glue string, pieces []string) string
- func InStringArray(needle string, haystack []string) bool
- func IsFloat(s string) bool
- func IsInt(s string) bool
- func IsSubDomain(subDomain, mainDomain string) bool
- func Join(array []string, sep string) string
- func JoinAny(array interface{}, sep string) string
- func Pos(haystack, needle string, startOffset ...int) int
- func PosI(haystack, needle string, startOffset ...int) int
- func PosIRune(haystack, needle string, startOffset ...int) int
- func PosR(haystack, needle string, startOffset ...int) int
- func PosRI(haystack, needle string, startOffset ...int) int
- func PosRIRune(haystack, needle string, startOffset ...int) int
- func PosRRune(haystack, needle string, startOffset ...int) int
- func PosRune(haystack, needle string, startOffset ...int) int
- func QuoteMeta(str string, chars ...string) string
- func Replace(origin, search, replace string, count ...int) string
- func ReplaceByArray(origin string, array []string) string
- func ReplaceByMap(origin string, replaces map[string]string) string
- func ReplaceI(origin, search, replace string, count ...int) string
- func ReplaceIByArray(origin string, array []string) string
- func ReplaceIByMap(origin string, replaces map[string]string) string
- func ReplaceIndex(s, old, new string, n int) string
- func ReplaceRegexMatch(regex, newStr, content string) (string, error)
- func ResolveAddress(addr []string) (string, error)
- func SetCacheDuration(duration time.Duration)
- func Split(str, delimiter string) []string
- func SplitAndTrim(str, delimiter string, characterMask ...string) []string
- func SubString(str string, start, end int) string
- func Trim(str string, characterMask ...string) string
- func TrimAll(str string, characterMask ...string) string
- func TrimLeft(str string, characterMask ...string) string
- func TrimLeftStr(str string, cut string, count ...int) string
- func TrimRight(str string, characterMask ...string) string
- func TrimRightStr(str string, cut string, count ...int) string
- func TrimStr(str string, cut string, count ...int) string
- func UnderLineName(name string) string
- type WordRankResult
- type WordRankResults
Constants ¶
const (
// NotFoundIndex is the position index for string not found in searching functions.
NotFoundIndex = -1
)
Variables ¶
This section is empty.
Functions ¶
func ChunkSplit ¶ added in v0.0.6
ChunkSplit 将字符串分割成小块
func ClearWordRankCache ¶ added in v0.0.3
func ClearWordRankCache()
ClearWordRankCache 清除 WordRank 函数的缓存
func Contains ¶ added in v0.1.6
Contains reports whether `substr` is within `str`, case-sensitively.
func ExtractRegexMatch ¶ added in v0.0.3
ExtractRegexMatch 提取正则表达式匹配的指定捕获组 参数:
- regex: 正则表达式字符串
- content: 要匹配的内容
- index: 捕获组索引
返回值:匹配的字符串和可能的错误
func InStringArray ¶ added in v0.0.3
InStringArray 检查字符串是否在切片中 参数:
- needle: 要查找的字符串
- haystack: 字符串切片
返回值:如果找到返回true,否则返回false
func IsSubDomain ¶ added in v0.0.6
IsSubDomain 检查 subDomain 是否为 mainDomain 的子域名。 支持在 mainDomain 中使用 '*' 通配符。
func QuoteMeta ¶
QuoteMeta 返回一个转义后的字符串,对特殊字符添加反斜杠(\) 如果提供了自定义字符集chars,则只转义这些字符 否则使用默认字符集: .\+*?[^]($){} str: 需要处理的字符串 chars: 可选的自定义字符集,只转义这些字符中包含的字符
func ReplaceByArray ¶
ReplaceByArray 使用字符串数组进行替换,区分大小写 array中的元素按照pairs处理:array[0]替换为array[1],array[2]替换为array[3],以此类推
func ReplaceByMap ¶
ReplaceByMap 使用map进行替换,区分大小写 replaces中的key会被替换为对应的value
func ReplaceIByArray ¶
ReplaceIByArray 使用字符串数组进行替换,不区分大小写 array中的元素按照pairs处理:array[0]替换为array[1],array[2]替换为array[3],以此类推
func ReplaceIByMap ¶
ReplaceIByMap 使用map进行替换,不区分大小写 replaces中的key会被替换为对应的value
func ReplaceIndex ¶ added in v0.0.3
ReplaceIndex 替换字符串中第n次出现的旧字符串 参数:
- s: 原字符串
- old: 要替换的旧字符串
- new: 新字符串
- n: 第几次出现(从0开始)
返回值:替换后的字符串
func ReplaceRegexMatch ¶ added in v0.0.3
ReplaceRegexMatch 使用新字符串替换所有正则表达式匹配项 参数:
- regex: 正则表达式字符串
- newStr: 用于替换的新字符串
- content: 要处理的内容
返回值:替换后的字符串和可能的错误
func SetCacheDuration ¶ added in v0.0.3
SetCacheDuration 设置缓存的过期时间
func SplitAndTrim ¶ added in v0.0.6
SplitAndTrim 分割字符串并对结果进行修剪
func SubString ¶ added in v0.0.3
SubString 截取字符串 参数:
- str: 输入字符串
- start: 起始位置
- end: 结束位置(如果为-1,则截取到字符串末尾)
返回值:截取后的字符串
func TrimLeftStr ¶ added in v0.0.7
TrimLeftStr 从字符串的开头去除所有给定的 cut 字符串 注意:它不会去除开头的空白字符
func TrimRightStr ¶ added in v0.0.7
TrimRightStr 从字符串的结尾去除所有给定的 cut 字符串 注意:它不会去除结尾的空白字符
Types ¶
type WordRankResult ¶ added in v0.0.3
type WordRankResult struct { Text string `json:"text"` Count int `json:"count"` Rank float32 `json:"rank"` }
WordRankResult 表示单词频率分析的结果
type WordRankResults ¶ added in v0.0.3
type WordRankResults []WordRankResult
WordRankResults 是 WordRankResult 的切片,实现了 sort.Interface
func WordRank ¶ added in v0.0.3
func WordRank(arrWords []string) WordRankResults
WordRank 对输入的单词切片进行词频分析 参数:
- arrWords: 单词切片
返回值:按词频排序的 WordRankResults
func (WordRankResults) Len ¶ added in v0.0.3
func (s WordRankResults) Len() int
func (WordRankResults) Less ¶ added in v0.0.3
func (s WordRankResults) Less(i, j int) bool
func (WordRankResults) Swap ¶ added in v0.0.3
func (s WordRankResults) Swap(i, j int)