Documentation ¶
Index ¶
- func After(str, ch string) string
- func AfterLast(str, ch string) string
- func Before(str, ch string) string
- func BeforeLast(str, ch string) string
- func BytesToString(bs []byte) string
- func CamelCase(str string) string
- func Capitalize(str string) string
- func Concat(length int, str ...string) string
- func ContainChinese(str string) bool
- func ContainLetter[T string | []byte](dat T) bool
- func ContainLower(str string) bool
- func ContainNumber[T string | []byte](dat T) bool
- func ContainUpper(str string) bool
- func ContainsAll(src string, substrs []string) bool
- func ContainsAny(src string, substrs []string) bool
- func Ellipsis(str string, size int) string
- func HammingDistance(str1, str2 string) (int, error)
- func HasPrefixAny(str string, prefixs ...string) bool
- func HasSuffixAny(str string, suffixs ...string) bool
- func HideString(src string, beg, end int, hideChar string) string
- func In(dst string, src []string) bool
- func IndexOffset(str, substr string, offset int) int
- func IsASCII(str string) bool
- func IsAllLower(str string) bool
- func IsAllUpper(str string) bool
- func IsAlpha(str string) bool
- func IsAmericanExpress(v string) bool
- func IsBase64(base64 string) bool
- func IsBase64URL(v string) bool
- func IsBin(dat string) bool
- func IsChinaUnionPay(v string) bool
- func IsChineseIDNum(id string) bool
- func IsChineseMobile(str string) bool
- func IsChinesePhone(phone string) bool
- func IsCreditCard(creditCart string) bool
- func IsDNS(str string) bool
- func IsEmail(str string) bool
- func IsEmptyString(str string) bool
- func IsFloat(v any) bool
- func IsFloatStr(str string) bool
- func IsGBK(data []byte) bool
- func IsHex(dat string) bool
- func IsIP(str string) bool
- func IsIPV4(str string) bool
- func IsIPV6(str string) bool
- func IsInt(v any) bool
- func IsIntStr(str string) bool
- func IsJSON(str string) bool
- func IsJWT(str string) bool
- func IsMasterCard(v string) bool
- func IsNotSpace(str string) bool
- func IsNumber(v any) bool
- func IsNumberStr(str string) bool
- func IsPort(str string) bool
- func IsPrint(str string) bool
- func IsRegexMatch(str, regex string) bool
- func IsSpace(str string) bool
- func IsString(val any) bool
- func IsStrongPassword(str string, length int) bool
- func IsURL(str string) bool
- func IsUnionPay(v string) bool
- func IsVisa(str string) bool
- func IsWeakPassword(str string) bool
- func IsZeroValue(val any) bool
- func KebabCase(str string) string
- func LowerFirst(str string) string
- func Pad(src string, size int, pad string) string
- func PadLeft(src string, size int, pad string) string
- func PadRight(src string, size int, pad string) string
- func RegexMatchAllGroups(str, pattern string) [][]string
- func RemoveNonPrintable(str string) string
- func RemoveWhiteSpace(str string, rmAll bool) string
- func ReplaceWithMap(str string, replaceMap map[string]string) string
- func Reverse(str string) string
- func Rotate(str string, shift int) string
- func Shuffle(str string) (string, error)
- func SnakeCase(str string) string
- func SplitAndTrim(str, delimeter string, cutset ...string) (vStr []string)
- func StringToBytes(str string) []byte
- func SubInBetween(str, beg, end string) string
- func SubString(src string, begin int, size int) string
- func Trim(str string, cutset ...string) string
- func UnWarp(str, sWarp string) string
- func UpperFirst(str string) string
- func UpperKebabCase(str string) string
- func UpperSnakeCase(str string) string
- func Warp(str, sWarp string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func After ¶
After returns the substring after the first occurrence of a specified string in the source string
Example: After("hello world", "o") -> " world"
func AfterLast ¶
AfterLast returns the substring after the last occurrence of a specified string in the source string
Example: AfterLast("hello world", "o") -> "rld"
func Before ¶
Before returns the string before the first occurrence of ch.
Example: Before("no-separator", "-") -> "no"
func BeforeLast ¶
BeforeLast returns the string before the last occurrence of ch.
Example: BeforeLast("abcabc", "c") -> "abcab"
func BytesToString ¶
BytesToString converts the byte slice to string without memory alloc.
func CamelCase ¶
CamelCase converts string to camelCase string. Non letters and numbers will be ignored.
Example: "!@#" -> "" "&FOO:BAR$BAZ" -> "fooBarBaz" "hello_world" -> "helloWorld"
func Capitalize ¶
Capitalize converts first character of string to upper case and the remaining to lower case.
Example: "hello" -> "Hello" "GoLang" -> "Golang"
func Concat ¶
Concat uses the strings.Builder to concatenate the input strings.
- `length` is the expected length of the concatenated string.
- If unsure about the length of string to be concatenated, length set to 0 / negetive number.
func ContainChinese ¶
ContainChinese check if the string contains Chinese characters.
func ContainLetter ¶
ContainLetter checks if the string contains any letters (a-zA-Z).
func ContainLower ¶
ContainLower checks if the string contains any lower letters (a-z).
func ContainNumber ¶
ContainNumber checks if the string contains any numbers (0-9).
func ContainUpper ¶
ContainUpper checks if the string contains any upper letters (A-Z).
func ContainsAll ¶
ContainsAll checks if the string contains all substrings.
func ContainsAny ¶
ContainsAny checks if the string contains any substring.
func Ellipsis ¶
Ellipsis returns a string with ellipsis if the string is longer than the specified size.
func HammingDistance ¶
HammingDistance returns the Hamming distance between two strings.
func HasPrefixAny ¶
HasPrefixAny checks if the string has any of the given prefixes.
func HasSuffixAny ¶
HasSuffixAny checks if the string has any of the given suffixes.
func HideString ¶
HideString hides the string between beg and end with the hideChar.
Example: HideString({"hello world", 3, 7, "*") -> "hel****orld"
func IndexOffset ¶
IndexOffset return the index of the first occurrence of the substring in the string after offset, or -1 if not found.
func IsAllLower ¶
IsAllLower checks if the string is all lower letters (a-z).
func IsAllUpper ¶
IsAllUpper checks if the string is all upper letters (A-Z).
func IsAmericanExpress ¶
IsAmericanExpress check if a give string is a valid american expression card nubmer or not.
func IsBase64URL ¶
IsBase64URL check if the string is a valid RUL-safe Base64 encoded string.
func IsChinaUnionPay ¶
IsChinaUnionPay check if a give string is a valid china union pay nubmer or not.
func IsChineseIDNum ¶
IsChineseIDNum check if the string is a valid Chinese ID card number.
func IsChineseMobile ¶
IsChineseMobile check if the string is a valid Chinese mobile phone number.
func IsChinesePhone ¶
IsChinesePhone check if the string is chinese phone number. Valid chinese phone is xxx-xxxxxxxx or xxxx-xxxxxxx.
func IsCreditCard ¶
IsCreditCard check if the string is credit card.
func IsEmptyString ¶
IsEmptyString check if the string is empty.
func IsFloatStr ¶
IsFloatStr check if the string can convert to a float.
func IsGBK ¶
IsGBK check if data encoding is gbk Note: this function is implemented by whether double bytes fall within the encoding range of gbk, while each byte of utf-8 encoding format falls within the encoding range of gbk. Therefore, utf8.valid() should be called first to check whether it is not utf-8 encoding, and then call IsGBK() to check gbk encoding. like below *
data := []byte("你好") if utf8.Valid(data) { fmt.Println("data encoding is utf-8") }else if(IsGBK(data)) { fmt.Println("data encoding is GBK") } fmt.Println("data encoding is unknown")
*
func IsInt ¶
IsInt check if value is a integer (int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr) or not.
func IsMasterCard ¶
IsMasterCard check if a give string is a valid master card nubmer or not.
func IsNotSpace ¶
IsNotSpace checks if the string is not whitespace, empty or not.
func IsNumberStr ¶
IsNumberStr check if the string can convert to a number.
func IsRegexMatch ¶
IsRegexMatch check if the string match the regexp.
func IsSpace ¶
IsSpace checks if the string is whitespace, empty or not.
Example: "" -> true " \t\n\r" -> true
func IsStrongPassword ¶
IsStrongPassword check if the string is strong password, if len(password) is less than the length param, return false.
Strong password: alpha(lower+upper) + number + special chars(!@#$%^&*()?><).
func IsUnionPay ¶
IsUnionPay check if a give string is a valid union pay nubmer or not.
func IsWeakPassword ¶
IsWeakPassword check if the string is weak password.
Weak password: only letter or only number or letter+number.
func KebabCase ¶
KebabCase converts string to kebab-case string, non letters and numbers will be ignored.
Example: "hello_world" -> "hello-world" "&FOO:BAR$BAZ" -> "foo-bar-baz"
func LowerFirst ¶
LowerFirst converts first character of string to lower case.
Example: "HELLO WORLD" -> "hELLO WORLD"
func Pad ¶
Pad pads the src to the left side and the right side with pad string until the src is size long.
func RegexMatchAllGroups ¶
RegexMatchAll returns all matches of the pattern in the string.
Example ("abc123",`(\w)(\w)(\w)`) -> [][]string{{"abc", "a", "b", "c"}, {"123", "1", "2", "3"}}
func RemoveNonPrintable ¶
RemoveNonPrintable removes all non-printable characters from the string.
func RemoveWhiteSpace ¶
RemoveWhiteSpace removes withespace from the string. When rmAll is true, all whitespaces are removed, otherwise only consective whitespaces are removed.
Example: RemoveWhiteSpace(" hello world ", false) -> "hello world" RemoveWitheSpace(" hello world ", true) -> "helloworld"
func ReplaceWithMap ¶
ReplaceWithMap returns a copy of `str`, which is replaced by a map in unordered way, case-sensitively.
func SnakeCase ¶
SnakeCase converts string to snake_case string, non letters and numbers will be ignored.
Example: "hello_world" -> "hello_world" "&FOO:BAR$BAZ" -> "foo_bar_baz"
func SplitAndTrim ¶
SplitAndTrim splits the string by the delimeter and trims the result.
Example: SplitAndTrim("a,b,cHello,d,eWorld,f", ",", "abc") -> []string{"Hello", "d", "eWorld", "f"}
func StringToBytes ¶
StringToBytes converts the string to byte slice without memory alloc.
func SubInBetween ¶
SubInBetween returns the substring between the beg and end.
func UnWarp ¶
UnWarp unwraps the string with the given string.
Example: UnWarp("*hello*", "*") -> "hello" UnWarp("abcdefabc", "abc") -> "def"
func UpperFirst ¶
UpperFirst converts first character of string to upper case.
Example: "hello" -> "Hello"
func UpperKebabCase ¶
UpperKebabCase converts string to upper KEBAB-CASE string, non letters and numbers will be ignored.
Example: "Hello World" -> "HELLO-WORLD" "!@#" -> ""
func UpperSnakeCase ¶
UpperSnakeCase converts string to upper SNAKE_CASE string, non letters and numbers will be ignored.
Example: "Hello World" -> "HELLO_WORLD" "!" -> ""
Types ¶
This section is empty.