Documentation ¶
Overview ¶
Package strKit
空白包括: " "(空格)、\r、\n、\t、\f
Package strKit ¶
PS: 字符串间的比较可以用 "==" 或 "strings.Compare()";
Index ¶
- func AppendIfMissing(str, suffix string) string
- func AssertStringNotBlank(str string) error
- func AssertStringNotEmpty(str string) error
- func BlankToDefault(str, def string) string
- func BytesToString(b []byte) string
- func Contains(s, substr string) bool
- func ContainsIgnoreCase(s, substr string) bool
- func Count(s, substr string) int
- func EmptyToDefault(str, def string, trimArgs ...bool) string
- func EndWith(s, suffix string) bool
- func Equals(str, str1 string) bool
- func EqualsIgnoreCase(str, str1 string) bool
- func Format(format string, args ...interface{}) stringdeprecated
- func GetChineseRuneCount(str string) (count int)
- func GetRuneCount(str string) int
- func HasChineseRune(str string) bool
- func HasEmpty(strings ...string) bool
- func Index(s, str string) int
- func IntToString(i int) string
- func IsAllEmpty(strings ...string) bool
- func IsAllNotEmpty(strings ...string) bool
- func IsBlank(str string) bool
- func IsEmpty(str string) bool
- func IsEmptyString(obj interface{}) bool
- func IsNotEmpty(str string) bool
- func Join(elements []string, sep string) string
- func LastIndex(s, str string) int
- func PrependIfMissing(str, prefix string) string
- func RemovePrefixIfExist(s, prefix string) string
- func RemoveSpace(str string) string
- func RemoveSuffixIfExist(s, suffix string) string
- func Replace(s, old, new string, n int) string
- func ReplaceAll(s, old, new string) string
- func ReplaceSpacesWithSpace(str string) string
- func Split(s, sep string) []string
- func StartWith(s, prefix string) bool
- func StringToBytes(s string) []byte
- func SubAfter(s string, index int) string
- func SubAfterString(s, str string) string
- func SubBefore(s string, index int) string
- func SubBeforeString(s, str string) string
- func Substring(str string, from, to int) string
- func ToBytes(str string) []byte
- func ToLower(s string) string
- func ToString(obj interface{}) string
- func ToStringE(obj interface{}) (string, error)
- func ToUpper(s string) string
- func Trim(str string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendIfMissing ¶
AppendIfMissing 如果给定字符串不是以给定的字符串为结尾,则在"尾部"添加结尾字符串(不忽略大小写).
PS: 区分大小写.
e.g. ("abc", "c")) => "abc" ("abc", "C")) => "abcC" ("abc", "0")) => "abc0"
func AssertStringNotBlank ¶ added in v2.0.17
func AssertStringNotEmpty ¶ added in v2.0.17
func BlankToDefault ¶
func BytesToString ¶
BytesToString converts byte slice to string without a memory allocation.
PS: (1) copy from gin/internal/bytesconv/bytesconv.go (2) Richelieu: 感觉这样效率更高,但慎用!!!
func Count ¶
Count 计数
@return >= 0
e.g. ("12345", "3") => 1 ("12345", "6") => 0
e.g.1 If substr is an empty string, Count returns 1 + the number of Unicode code points in s. strKit.Count("12345", "") => 6
func EndWith ¶
EndWith
PS: 区分大小写.
@param s suffix不为""的情况下,如果s为"",返回值必定为false @param suffix 如果suffix为"",返回值必定为true
e.g. ""的情况 ("", "") => true ("1", "") => true ("", "1") => false
e.g.1 区分大小写 ("abc", "abc") => true ("abc", "Abc") => false
func GetRuneCount ¶
GetRuneCount
PS: (1) 包括简体、繁体. (2) 如果确定 传参str 中不存在中文字符,建议直接使用 内置函数len().
@param str (可能)带有 中文字符 的字符串
e.g. ("test") => 4 ("测试") => 2
func Index ¶
Index
PS: (1) s中不存在substr的话,返回-1 (2) s中存在多个substr的话,返回第一个的下标
@param s 被查找的字符串 @param str 查找的字符串
e.g. ("abcabc", "ab") => 0 ("bcabc", "ab") => 2 ("23", "1") => -1
func IntToString ¶
func IsAllEmpty ¶
func IsAllNotEmpty ¶
func IsEmptyString ¶
func IsEmptyString(obj interface{}) bool
func IsNotEmpty ¶
func PrependIfMissing ¶
PrependIfMissing 如果给定字符串不是以给定的字符串为开头,则在"首部"添加 起始字符串.
PS: 区分大小写.
e.g. ("abc", "a") => "abc" ("abc", "A")) => "Aabc" ("abc", "0") => "0abc"
func RemovePrefixIfExist ¶
RemovePrefixIfExist 去掉指定的"前缀"(如果存在的话)
PS: (1) 区分大小写; (2) 存在多个的话,只会移除第1个.
@param s 如果为"",返回"" @param prefix 如果为"",返回传参s
e.g. ""的情况 ("", "") => "" ("1", "") => "1" ("", "1") => ""
e.g.1 区分大小写 ("abcd", "abcd") => "" ("abcd", "Abcd") => "abcd"
func RemoveSpace ¶
RemoveSpace 移除str中所有的(包括左右的、中间的):" "、"\t"、"\r"、"\n"...
e.g. (" \t\r\n \n\n") => ""
func RemoveSuffixIfExist ¶
RemoveSuffixIfExist 去掉指定的"后缀"(如果存在的话)
PS: (1) 区分大小写; (2) 存在多个的话,只会移除最后1个.
func ReplaceSpacesWithSpace ¶
ReplaceSpacesWithSpace 将连续的空格替换为单个空格
e.g. "It\tis\na\fsimple\rtest !" => "It is a simple test !"
func Split ¶
Split
@param sep 可以为"",此种情况比较特殊,详见下例;
如果s中不存在sep,那么返回切片的长度为1
@return 必定不为nil && len >= 1
e.g. ("", "-") => [](长度为1;唯一的元素为"") ("-", "-") => []string{"", ""} ("123-", "-") => []string{"123", ""} e.g.1 ("hello world!", "") => [h e l l o w o r l d !] ("1-2-3", "-") => [1 2 3](长度为3) ("1-2-3", "+") => [1-2-3](长度为1) ("172.18.21.50;8095;", ";") => [172.18.21.50 8095 ](长度为3,第三个元素为"")
func StartWith ¶
StartWith
PS: 区分大小写.
@param s prefix不为""的情况下,如果s为"",返回值必定为false @param prefix 如果prefix为"",返回值必定为true
e.g. ""的情况 ("", "") => true ("1", "") => true ("", "1") => false
e.g.1 区分大小写 ("abc", "abc") => true ("abc", "Abc") => false
func StringToBytes ¶
StringToBytes converts string to byte slice without a memory allocation.
PS: (1) copy from gin/internal/bytesconv/bytesconv.go (2) Richelieu: 感觉这样效率更高,但慎用!!!
func SubAfterString ¶
SubAfterString
case 1: s包含str的情况,返回截取后的字符串; case 2: s不包含str的情况,直接返回s.
e.g. ("abcd", "bc") => "bcd"
func SubBeforeString ¶
SubBeforeString
case 1: s包含str的情况,返回截取后的字符串; case 2: s不包含str的情况,直接返回s.
e.g. ("abcd", "bc") => "a"
Types ¶
This section is empty.