stringutils

package
v0.0.0-...-98f1bff Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: Unlicense Imports: 3 Imported by: 0

Documentation

Overview

Package stringutils 提供了常用的字符串操作工具函数 Package stringutils provides common string utility functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(str string) string

Capitalize 将字符串的第一个字符转为大写 Capitalize converts the first character of a string to uppercase

func Center

func Center(str string, size int, padChar rune) string

Center 在字符串两侧填充指定字符使其居中 Center pads both sides of a string with a specified character to center it within a specified length

func ContainsAll

func ContainsAll(str string, searchStrs ...string) bool

ContainsAll 检查字符串是否包含所有子字符串 ContainsAll checks if a string contains all of the specified substrings

func ContainsAny

func ContainsAny(str string, searchStrs ...string) bool

ContainsAny 检查字符串是否包含任意一个子字符串 ContainsAny checks if a string contains any of the specified substrings

func CountMatches

func CountMatches(str string, sub string) int

CountMatches 计算字符串中指定子字符串出现的次数 CountMatches counts the number of occurrences of a substring in a string

func DefaultIfBlank

func DefaultIfBlank(str string, defaultStr string) string

DefaultIfBlank 如果字符串为空白则返回默认值 DefaultIfBlank returns a default value if a string is blank

func DefaultIfEmpty

func DefaultIfEmpty(str string, defaultStr string) string

DefaultIfEmpty 如果字符串为空则返回默认值 DefaultIfEmpty returns a default value if a string is empty

func EndsWith

func EndsWith(str string, suffix string) bool

EndsWith 检查字符串是否以指定后缀结束 EndsWith checks if a string ends with a specified suffix

func EqualsIgnoreCase

func EqualsIgnoreCase(str1 string, str2 string) bool

EqualsIgnoreCase 忽略大小写比较两个字符串 EqualsIgnoreCase compares two strings ignoring case

func IsBlank

func IsBlank(str string) bool

IsBlank 检查字符串是否为空白(空或只包含空白字符) IsBlank checks if a string is blank (empty or contains only whitespace)

func IsEmpty

func IsEmpty(str string) bool

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

func IsNotBlank(str string) bool

IsNotBlank 检查字符串是否非空白 IsNotBlank checks if a string is not blank

func IsNotEmpty

func IsNotEmpty(str string) bool

IsNotEmpty 检查字符串是否非空 IsNotEmpty checks if a string is not empty

func Join

func Join(separator string, elements ...string) string

Join 使用分隔符连接字符串数组 Join concatenates the elements of a string array into a single string with a separator

func PadCenter

func PadCenter(str string, size int, padChar rune) string

PadCenter 在字符串两侧填充字符,使其居中 PadCenter pads a string on both sides with a specified character

func PadLeft

func PadLeft(str string, size int, padChar rune) string

PadLeft 在字符串左侧填充指定字符到指定长度 PadLeft pads the left side of a string with a specified character to a specified length

func PadRight

func PadRight(str string, size int, padChar rune) string

PadRight 在字符串右侧填充指定字符到指定长度 PadRight pads the right side of a string with a specified character to a specified length

func RemoveEnd

func RemoveEnd(str string, remove string) string

RemoveEnd 移除字符串结尾的指定后缀 RemoveEnd removes a suffix from the end of a string

func RemoveStart

func RemoveStart(str string, remove string) string

RemoveStart 移除字符串开头的指定前缀 RemoveStart removes a prefix from the start of a string

func Repeat

func Repeat(str string, repeat int) string

Repeat 重复字符串指定次数 Repeat returns a string consisting of a specified number of copies of the original string

func Replace

func Replace(str string, oldStr string, newStr string, count int) string

Replace 替换字符串中的指定子字符串 Replace replaces a specified substring with another substring in a string

func ReplaceAll

func ReplaceAll(str string, oldStr string, newStr string) string

ReplaceAll 替换字符串中所有的指定子字符串 ReplaceAll replaces all occurrences of a specified substring with another substring in a string

func Reverse

func Reverse(str string) string

Reverse 反转字符串 Reverse reverses a string

func ReverseString

func ReverseString(str string) string

ReverseString 反转字符串 ReverseString reverses a string

func Split

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

Split 使用分隔符分割字符串 Split divides a string into substrings using a separator

func StartsWith

func StartsWith(str string, prefix string) bool

StartsWith 检查字符串是否以指定前缀开始 StartsWith checks if a string starts with a specified prefix

func SubstringAfter

func SubstringAfter(str string, separator string) string

SubstringAfter 返回字符串中指定分隔符之后的子字符串 SubstringAfter returns the substring after the first occurrence of a separator

func SubstringBefore

func SubstringBefore(str string, separator string) string

SubstringBefore 返回字符串中指定分隔符之前的子字符串 SubstringBefore returns the substring before the first occurrence of a separator

func SwapCase

func SwapCase(str string) string

SwapCase 交换字符串中字母的大小写 SwapCase swaps the case of all alphabetic characters in a string

func ToLowerCase

func ToLowerCase(str string) string

ToLowerCase 将字符串转为小写 ToLowerCase converts a string to lowercase

func ToUpperCase

func ToUpperCase(str string) string

ToUpperCase 将字符串转为大写 ToUpperCase converts a string to uppercase

func Trim

func Trim(str string) string

Trim 去除字符串两端的空白字符 Trim removes whitespace from both ends of a string

func TrimToEmpty

func TrimToEmpty(str string) string

TrimToEmpty 去除字符串两端的空白字符,如果结果为nil则返回空字符串 TrimToEmpty removes whitespace from both ends of a string, returns empty string if result is nil

func Truncate

func Truncate(str string, maxWidth int) string

Truncate 截断字符串到指定长度 Truncate truncates a string to a specified length

func TruncateWithSuffix

func TruncateWithSuffix(str string, maxWidth int, suffix string) string

TruncateWithSuffix 截断字符串到指定长度并添加后缀 TruncateWithSuffix truncates a string to a specified length and adds a suffix

func Uncapitalize

func Uncapitalize(str string) string

Uncapitalize 将字符串的第一个字符转为小写 Uncapitalize converts the first character of a string to lowercase

Types

This section is empty.

Jump to

Keyboard shortcuts

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