Documentation
¶
Index ¶
- func CamelToSnake(s string) string
- func ContainsAll(s string, substrs ...string) bool
- func ContainsAny(s string, substrs ...string) bool
- func Ellipsis(str string, maxLength int) string
- func Reverse(s string) string
- func SnakeToCamel(s string) string
- func SnakeToPascal(s string) string
- func TakeFirst(s string, n int) string
- func TrimFirstPrefix(s string, prefixes ...string) string
- func TrimFirstSuffix(s string, suffixes ...string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelToSnake ¶
CamelToSnake 将驼峰式字符串转换为下划线连接
- PascalCase -> pascal_case
- lowerCamelCase -> lower_camel_case
- HTTPRequest -> http_request
- MyID -> my_id
- ID -> id
func ContainsAll ¶
ContainsAll 判断字符串 s 是否包含 substrs 中的所有子串
Examples: ¶
ContainsAll("hello world", "hello", "world") // true
ContainsAll("hello world", "hello", "world", "123") // false
func ContainsAny ¶
ContainsAny 判断字符串 s 是否包含 substrs 中的任意一个子串
Examples: ¶
ContainsAny("hello world", "world", "123") // true
ContainsAny("hello world", "123") // false
func Ellipsis ¶
Ellipsis 截取字符串,并在末尾添加省略号
Params: ¶
str: 待截取的字符串 maxLength: 最大长度
Examples: ¶
Ellipsis("hello world", 5) // he...
Ellipsis("你好 世界!", 3) // ...
Ellipsis("你好 世界!", 5) // 你好...
func SnakeToCamel ¶
SnakeToCamel 将下划线连接的字符串转换为小驼峰式
- my_var -> myVar
- http_request -> httpRequest
- _my_var -> myVar
func SnakeToPascal ¶
SnakeToPascal 将下划线连接的字符串转换为大驼峰式(PascalCase)
- my_var -> MyVar
- http_request -> HttpRequest
- _my_var -> MyVar
func TakeFirst ¶
TakeFirst 截取字符串前 n 个 Unicode 字符(rune)
Params: ¶
s: 字符串 maxLength: 字符长度
Examples: ¶
Truncate("hello world", 5) // hello
Truncate("你好 世界!", 2) // 你好
func TrimFirstPrefix ¶
TrimFirstPrefix 移除字符串中首个匹配的前缀
Examples: ¶
TrimFirstPrefix("hello_world", "hello", "_world") // _world
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.