Documentation
¶
Overview ¶
Package stringutils 提供了常用的字符串操作工具函数 Package stringutils provides common string utility functions
Index ¶
- func Capitalize(str string) string
- func Center(str string, size int, padChar rune) string
- func ContainsAll(str string, searchStrs ...string) bool
- func ContainsAny(str string, searchStrs ...string) bool
- func CountMatches(str string, sub string) int
- func DefaultIfBlank(str string, defaultStr string) string
- func DefaultIfEmpty(str string, defaultStr string) string
- func EndsWith(str string, suffix string) bool
- func EqualsIgnoreCase(str1 string, str2 string) bool
- func IsBlank(str string) bool
- func IsEmpty(str string) bool
- func IsNotBlank(str string) bool
- func IsNotEmpty(str string) bool
- func Join(separator string, elements ...string) string
- func PadCenter(str string, size int, padChar rune) string
- func PadLeft(str string, size int, padChar rune) string
- func PadRight(str string, size int, padChar rune) string
- func RemoveEnd(str string, remove string) string
- func RemoveStart(str string, remove string) string
- func Repeat(str string, repeat int) string
- func Replace(str string, oldStr string, newStr string, count int) string
- func ReplaceAll(str string, oldStr string, newStr string) string
- func Reverse(str string) string
- func ReverseString(str string) string
- func Split(str string, separator string) []string
- func StartsWith(str string, prefix string) bool
- func SubstringAfter(str string, separator string) string
- func SubstringBefore(str string, separator string) string
- func SwapCase(str string) string
- func ToLowerCase(str string) string
- func ToUpperCase(str string) string
- func Trim(str string) string
- func TrimToEmpty(str string) string
- func Truncate(str string, maxWidth int) string
- func TruncateWithSuffix(str string, maxWidth int, suffix string) string
- func Uncapitalize(str string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Capitalize ¶
Capitalize 将字符串的第一个字符转为大写 Capitalize converts the first character of a string to uppercase
func Center ¶
Center 在字符串两侧填充指定字符使其居中 Center pads both sides of a string with a specified character to center it within a specified length
func ContainsAll ¶
ContainsAll 检查字符串是否包含所有子字符串 ContainsAll checks if a string contains all of the specified substrings
func ContainsAny ¶
ContainsAny 检查字符串是否包含任意一个子字符串 ContainsAny checks if a string contains any of the specified substrings
func CountMatches ¶
CountMatches 计算字符串中指定子字符串出现的次数 CountMatches counts the number of occurrences of a substring in a string
func DefaultIfBlank ¶
DefaultIfBlank 如果字符串为空白则返回默认值 DefaultIfBlank returns a default value if a string is blank
func DefaultIfEmpty ¶
DefaultIfEmpty 如果字符串为空则返回默认值 DefaultIfEmpty returns a default value if a string is empty
func EqualsIgnoreCase ¶
EqualsIgnoreCase 忽略大小写比较两个字符串 EqualsIgnoreCase compares two strings ignoring case
func IsBlank ¶
IsBlank 检查字符串是否为空白(空或只包含空白字符) IsBlank checks if a string is blank (empty or contains only whitespace)
func IsEmpty ¶
IsEmpty 检查字符串是否为空
参数 / Parameters:
str - 要检查的字符串 / string to check
返回值 / Returns:
bool - 如果字符串为空返回true,否则返回false / true if string is empty, false otherwise
示例 / Example:
IsEmpty("") // true IsEmpty("abc") // false
IsEmpty checks if a string is empty
func IsNotBlank ¶
IsNotBlank 检查字符串是否非空白 IsNotBlank checks if a string is not blank
func IsNotEmpty ¶
IsNotEmpty 检查字符串是否非空 IsNotEmpty checks if a string is not empty
func Join ¶
Join 使用分隔符连接字符串数组 Join concatenates the elements of a string array into a single string with a separator
func PadCenter ¶
PadCenter 在字符串两侧填充字符,使其居中 PadCenter pads a string on both sides with a specified character
func PadLeft ¶
PadLeft 在字符串左侧填充指定字符到指定长度 PadLeft pads the left side of a string with a specified character to a specified length
func PadRight ¶
PadRight 在字符串右侧填充指定字符到指定长度 PadRight pads the right side of a string with a specified character to a specified length
func RemoveStart ¶
RemoveStart 移除字符串开头的指定前缀 RemoveStart removes a prefix from the start of a string
func Repeat ¶
Repeat 重复字符串指定次数 Repeat returns a string consisting of a specified number of copies of the original string
func Replace ¶
Replace 替换字符串中的指定子字符串 Replace replaces a specified substring with another substring in a string
func ReplaceAll ¶
ReplaceAll 替换字符串中所有的指定子字符串 ReplaceAll replaces all occurrences of a specified substring with another substring in a string
func ReverseString ¶
ReverseString 反转字符串 ReverseString reverses a string
func StartsWith ¶
StartsWith 检查字符串是否以指定前缀开始 StartsWith checks if a string starts with a specified prefix
func SubstringAfter ¶
SubstringAfter 返回字符串中指定分隔符之后的子字符串 SubstringAfter returns the substring after the first occurrence of a separator
func SubstringBefore ¶
SubstringBefore 返回字符串中指定分隔符之前的子字符串 SubstringBefore returns the substring before the first occurrence of a separator
func SwapCase ¶
SwapCase 交换字符串中字母的大小写 SwapCase swaps the case of all alphabetic characters in a string
func ToLowerCase ¶
ToLowerCase 将字符串转为小写 ToLowerCase converts a string to lowercase
func ToUpperCase ¶
ToUpperCase 将字符串转为大写 ToUpperCase converts a string to uppercase
func TrimToEmpty ¶
TrimToEmpty 去除字符串两端的空白字符,如果结果为nil则返回空字符串 TrimToEmpty removes whitespace from both ends of a string, returns empty string if result is nil
func TruncateWithSuffix ¶
TruncateWithSuffix 截断字符串到指定长度并添加后缀 TruncateWithSuffix truncates a string to a specified length and adds a suffix
func Uncapitalize ¶
Uncapitalize 将字符串的第一个字符转为小写 Uncapitalize converts the first character of a string to lowercase
Types ¶
This section is empty.