stringx

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-01 22:06:35 * @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-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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPrefixIfNot

func AddPrefixIfNot(str string, prefix string) string

AddPrefixIfNot 如果给定字符串不是以prefix开头的,在开头补充 prefix

func AddSuffixIfNot

func AddSuffixIfNot(str string, suffix string) string

AddSuffixIfNot 如果给定字符串不是以suffix结尾的,在尾部补充 suffix

func CalculateMD5Hash

func CalculateMD5Hash(input string) string

CalculateMD5Hash 计算string md5 hash值

func CleanEmpty

func CleanEmpty(str string) string

CleanEmpty 清除空白串

func CompareIgnoreCase

func CompareIgnoreCase(str1 string, str2 string) int

CompareIgnoreCase 比较两个字符串,用于排序(大小写不敏感)

0 相等;<0 小于; >0 大于

func Contains

func Contains(value string, searchStr string) bool

Contains 指定字符是否在字符串中出现过

func ContainsAll

func ContainsAll(str string, searchStrs []string) bool

ContainsAll 检查指定字符串中是否含给定的所有字符串

func ContainsAny

func ContainsAny(value string, searchStrs []string) bool

ContainsAny 查找指定字符串是否包含指定字符串列表中的任意一个字符串

func ContainsAnyIgnoreCase

func ContainsAnyIgnoreCase(str string, searchStrs []string) bool

ContainsAnyIgnoreCase 找指定字符串是否包含指定字符串列表中的任意一个字符串(忽略大小写)

func ContainsBlank

func ContainsBlank(str string) bool

ContainsBlank 给定字符串是否包含空白符(空白符包括空格、制表符、全角空格和不间断空格)

func ContainsIgnoreCase

func ContainsIgnoreCase(value string, searchStr string) bool

ContainsIgnoreCase 指定字符是否在字符串中出现过(忽略大小写)

func Count

func Count(str string, searchStr string) int

Count 统计指定内容中包含指定字符串的数量

func Cut

func Cut(str string, n int) []string

Cut 将字符串切分为n等份

func EndWith

func EndWith(str string, suffix string) bool

EndWith 是否以指定字符串结尾

func EndWithAny

func EndWithAny(str string, suffixes []string) bool

EndWithAny 给定字符串是否以任何一个字符串结尾 给定字符串和数组为空都返回false

func EndWithAnyIgnoreCase

func EndWithAnyIgnoreCase(str string, suffixes []string) bool

EndWithAnyIgnoreCase 给定字符串是否以任何一个字符串结尾(忽略大小写) 给定字符串和数组为空都返回false

func EndWithIgnoreCase

func EndWithIgnoreCase(str string, suffix string) bool

EndWithIgnoreCase 是否以指定字符串结尾,忽略大小写

func Equals

func Equals(str1 string, str2 string) bool

Equals 比较2个字符串(大小写敏感)

func EqualsAny

func EqualsAny(str1 string, str2 []string) bool

EqualsAny 给定字符串是否与提供的中任一字符串相同,相同则返回true,没有相同的返回false; 如果参与比对的字符串列表为空,返回false

func EqualsAnyIgnoreCase

func EqualsAnyIgnoreCase(str1 string, str2 []string) bool

EqualsAnyIgnoreCase 给定字符串是否与提供的中任一字符串相同(忽略大小写),相同则返回true,没有相同的返回false; 如果参与比对的字符串列表为空,返回false

func EqualsAt

func EqualsAt(value string, position int, subStr string) bool

EqualsAt 字符串指定位置的字符是否与给定字符相同

func EqualsIgnoreCase

func EqualsIgnoreCase(str1 string, str2 string) bool

EqualsIgnoreCase 比较2个字符串(大小写不敏感)

func ExtractValue

func ExtractValue(extra string, key string, searchPrefix string) string

ExtractValue 从给定的字符串中提取指定的键的值

func Fill

func Fill(str string, char string, length int, isPre bool) string

Fill 将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串

func FillAfter

func FillAfter(str string, char string, length int) string

FillAfter 将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串

func FillBefore

func FillBefore(str string, char string, length int) string

FillBefore 将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串

func Format

func Format(template string, params map[string]interface{}) string

Format 通过map中的参数 格式化字符串 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) ---=》 aValue and bValue

func GetContainsStr

func GetContainsStr(str string, searchStrs []string) string

GetContainsStr 查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串 不存在返回空串

func Hide

func Hide(str string, startInclude int, endExclude int) string

Hide 替换指定字符串的指定区间内字符为"*" 俗称:脱敏功能

func IndexOf

func IndexOf(str string, subStr string) int

IndexOf 返回字符在原始字符串的下标

func IndexOfByRange

func IndexOfByRange(str string, subStr string, start int, end int) int

IndexOfByRange 指定范围内查找指定字符

func IndexOfByRangeStart

func IndexOfByRangeStart(str string, subStr string, start int) int

IndexOfByRangeStart 指定范围内查找指定字符

func IndexOfIgnoreCase

func IndexOfIgnoreCase(str string, subStr string) int

IndexOfIgnoreCase 返回字符在原始字符串的下标(大小写不敏感)

func IndexOfIgnoreCaseByRange

func IndexOfIgnoreCaseByRange(str string, subStr string, start int) int

IndexOfIgnoreCaseByRange 从指定下标开始,返回在字符串中的下标 (大小不敏感)

func IndexedFormat

func IndexedFormat(template string, params []interface{}) string

IndexedFormat 有序的格式化文本,使用{number}做为占位符 通常使用:format("this is {0} for {1}", "a", "b") =》 this is a for b

func InsertSpaces

func InsertSpaces(str string, interval int) string

InsertSpaces 插入空值 InsertSpaces 插入空值

func LastIndexOf

func LastIndexOf(str string, subStr string) int

LastIndexOf 返回最后出现指定字符串的下标

func LastIndexOfByRangeStart

func LastIndexOfByRangeStart(str string, subStr string, start int) int

LastIndexOfByRangeStart 从指定下标开始,返回最后出现指定字符串的下标

func LastIndexOfIgnoreCase

func LastIndexOfIgnoreCase(str string, subStr string) int

LastIndexOfIgnoreCase 返回最后出现指定字符串的下标(大小写不敏感)

func Length

func Length(str string) int

Length 计算长度

func OrdinalIndexOf

func OrdinalIndexOf(str string, subStr string, ordinal int, start ...int) int

OrdinalIndexOf 返回字符串 subStr 在字符串 str 中第 ordinal 次出现的位置。 如果 str="" 或 subStr=" 或 ordinal≥0 则返回-1

func Pad

func Pad(input string, minLength int, paddler ...*Paddler) string

Pad 输入的字符长度<minLength时自动补位*

func RemoveAll

func RemoveAll(str string, strToRemove string) string

RemoveAll 移除字符串中所有给定字符串;removeAll("aa-bb-cc-dd", "-") =》 aabbccdd

func RemoveAllLineBreaks

func RemoveAllLineBreaks(str string) string

RemoveAllLineBreaks 去除所有换行符,包括:\r \n

func RemoveAny

func RemoveAny(str string, strsToRemove []string) string

RemoveAny 移除字符串中所有给定字符串,当某个字符串出现多次,则全部移除

func RemovePrefix

func RemovePrefix(str string, prefix string) string

RemovePrefix 去掉指定前缀

func RemovePrefixIgnoreCase

func RemovePrefixIgnoreCase(str string, prefix string) string

RemovePrefixIgnoreCase 忽略大小写去掉指定前缀

func RemoveSuffix

func RemoveSuffix(str string, suffix string) string

RemoveSuffix 去掉指定后缀

func RemoveSuffixIgnoreCase

func RemoveSuffixIgnoreCase(str string, suffix string) string

RemoveSuffixIgnoreCase 去掉指定后缀(忽略大小写)

func Repeat

func Repeat(str string, count int) string

Repeat 重复字符串

func RepeatAndJoin

func RepeatAndJoin(str string, delimiter string, count int) string

RepeatAndJoin 重复某个字符串并通过分界符连接

func RepeatByLength

func RepeatByLength(str string, padLen int) string

RepeatByLength 重复某个字符串到指定长度

func Replace

func Replace(source string, searchStr string, replacement string, replaceCount int) string

Replace 替换字符串

func ReplaceAll

func ReplaceAll(source string, searchStr string, replacement string) string

ReplaceAll 替换字符串

func ReplaceAllIgnoreCase

func ReplaceAllIgnoreCase(source string, searchStr string, replacement string) string

ReplaceAllIgnoreCase 替换字符串

func ReplaceIgnoreCase

func ReplaceIgnoreCase(source string, searchStr string, replacement string, replaceCount int) string

ReplaceIgnoreCase 替换字符串

func ReplaceSpecialChars

func ReplaceSpecialChars(str string, replaceValue rune) string

ReplaceSpecialChars 去掉特殊符号、转为自定义

func ReplaceWithIndex

func ReplaceWithIndex(str string, startIndex int, endIndex int, replacedStr string) string

ReplaceWithIndex 按照指定区间替换字符串 startIndex 开始位置(包含) endIndex 结束位置(不包含)

func ReplaceWithMatcher

func ReplaceWithMatcher(str string, regex string, replaceFun func(string) string) string

ReplaceWithMatcher 通过正则表达式替换字符串

func Reverse

func Reverse(str string) string

Reverse 反转给定的字符串

func SafeIndexOfByRange

func SafeIndexOfByRange(str string, subStr string, options ...func(*searchOptions)) (index int)

SafeIndexOfByRange 在指定范围内查找指定字符,避免下标溢出

func SetPadPosition

func SetPadPosition(p *Paddler, position PadPosition)

func Split

func Split(str string, separator string) []string

Split 分割字符串

func SplitAfterMapping

func SplitAfterMapping[T any](str string, separator string, mapping func(s string) (T, error)) []T

SplitAfterMapping 切分字符串,切分之后通过mapping转换并返回

func SplitByLen

func SplitByLen(str string, length int) []string

SplitByLen 根据给定长度,将给定字符串截取为多个部分

func SplitLimit

func SplitLimit(str string, separator string, limit int) []string

SplitLimit 分割字符串,限制分片数

func SplitTrim

func SplitTrim(str string, separator string) []string

SplitTrim 切分字符串,去除切分后每个元素两边的空白符,去除空白项

func SplitTrimLimit

func SplitTrimLimit(str string, separator string, limit int) []string

SplitTrimLimit 切分字符串,去除切分后每个元素两边的空白符,去除空白项,限制分片数

func StartWith

func StartWith(str string, prefix string) bool

StartWith 字符串是否以给定字符开始

func StartWithAny

func StartWithAny(str string, prefixes []string) bool

StartWithAny 给定字符串是否以任何一个字符串开始; 给定字符串和数组为空都返回false

func StartWithAnyIgnoreCase

func StartWithAnyIgnoreCase(str string, prefixes []string) bool

StartWithAnyIgnoreCase 给定字符串是否以任何一个字符串开始(忽略大小写) 给定字符串和数组为空都返回false

func StartWithIgnoreCase

func StartWithIgnoreCase(str string, prefix string) bool

StartWithIgnoreCase 字符串是否以给定字符开始-忽略大小写

func SubAfter

func SubAfter(str string, separator string, isLastSeparator bool) string

SubAfter 截取分隔字符串之后的字符串,不包括分隔字符串

func SubBefore

func SubBefore(str string, separator string, isLastSeparator bool) string

SubBefore 截取分隔字符串之前的字符串,不包括分隔字符串 isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个

func SubBetween

func SubBetween(str string, before string, after string) string

SubBetween 截取指定字符串中间部分,不包括标识字符串

func SubBetweenAll

func SubBetweenAll(str string, prefix string, suffix string) []string

SubBetweenAll 截取指定字符串多段中间部分,不包括标识字符串

func Trim

func Trim(str string) string

Trim 除去字符串头尾部的空白

func TrimEnd

func TrimEnd(str string) string

TrimEnd 除去字符串尾部的空白

func TrimStart

func TrimStart(str string) string

TrimStart 除去字符串头部的空白

func Truncate

func Truncate(str string, maxBytes int) string

Truncate 截断字符串,使用不超过maxBytes长度

func TruncateAppendEllipsis

func TruncateAppendEllipsis(str string, maxBytes int) string

TruncateAppendEllipsis 截断字符串,使用不超过maxBytes长度。截断后自动追加省略号(...) 用于存储数据库varchar且编码为UTF-8的字段

func WithEnd

func WithEnd(end int) func(*searchOptions)

WithEnd 用于配置结束位置

func WithStart

func WithStart(start int) func(*searchOptions)

WithStart 用于配置起始位置

Types

type PadPosition

type PadPosition int
const (
	Left PadPosition = iota
	Right
	Middle
)

type Paddler

type Paddler struct {
	Position PadPosition
}

Jump to

Keyboard shortcuts

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