dstr

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotFoundIndex 字符串搜索的时候,没有找到字符串的位置,则返回-1
	NotFoundIndex = -1
)

Variables

This section is empty.

Functions

func AddSlashes added in v0.0.10

func AddSlashes(str string) string

AddSlashes 给引号加反斜杠

func CamelCase added in v0.1.9

func CamelCase(s string) string

CamelCase converts a string to CamelCase. Deprecated, use CaseCamel instead.

func CamelLowerCase added in v0.1.9

func CamelLowerCase(s string) string

CamelLowerCase converts a string to lowerCamelCase. Deprecated, use CaseCamelLower instead.

func CaseCamel added in v0.1.9

func CaseCamel(s string) string

CaseCamel converts a string to CamelCase.

func CaseCamelLower added in v0.1.9

func CaseCamelLower(s string) string

CaseCamelLower converts a string to lowerCamelCase.

func CaseDelimited added in v0.1.9

func CaseDelimited(s string, del uint8) string

CaseDelimited converts a string to snake.case.delimited.

func CaseDelimitedScreaming added in v0.1.9

func CaseDelimitedScreaming(s string, del uint8, screaming bool) string

CaseDelimitedScreaming converts a string to DELIMITED.SCREAMING.CASE or delimited.screaming.case.

func CaseKebab added in v0.1.9

func CaseKebab(s string) string

CaseKebab converts a string to kebab-case

func CaseKebabScreaming added in v0.1.9

func CaseKebabScreaming(s string) string

CaseKebabScreaming converts a string to KEBAB-CASE-SCREAMING.

func CaseSnake added in v0.1.9

func CaseSnake(s string) string

CaseSnake converts a string to snake_case.

func CaseSnakeFirstUpper added in v0.1.9

func CaseSnakeFirstUpper(word string, underscore ...string) string

CaseSnakeFirstUpper converts a string like "RGBCodeMd5" to "rgb_code_md5". TODO for efficiency should change regexp to traversing string in future.

func CaseSnakeScreaming added in v0.1.9

func CaseSnakeScreaming(s string) string

CaseSnakeScreaming converts a string to SNAKE_CASE_SCREAMING.

func Chr added in v0.0.10

func Chr(ascii int) string

Chr return the ascii string of a number(0-255).

func ChunkSplit added in v0.0.10

func ChunkSplit(body string, chunkLen int, end string) string

ChunkSplit 将字符串分割成更小的块

func Compare added in v0.0.10

func Compare(a, b string) int

Compare 返回一个整数,按字典顺序比较两个字符串。 如果返回 0 表示 a==b, -1 表示 a < b, +1 表示 a > b.

func CompareVersion added in v0.0.10

func CompareVersion(a, b string) int

CompareVersion 对比 <a> and <b> as 标准 GNU 版本. It returns 1 if <a> > <b>. It returns -1 if <a> < <b>. It returns 0 if <a> = <b>. GNU standard version is like: v1.0 1 1.0.0 v1.0.1 v2.10.8 10.2.0 etc.

func CompareVersionGo added in v0.0.10

func CompareVersionGo(a, b string) int

CompareVersionGo 比较 <a> and <b> as 标准的 Golang 版本. It returns 1 if <a> > <b>. It returns -1 if <a> < <b>. It returns 0 if <a> = <b>. Golang standard version is like: 1.0.0 v1.0.1 v2.10.8 10.2.0 v0.0.0-20190626092158-b2ccc519800e v4.20.0+incompatible etc.

func Contains added in v0.0.3

func Contains(str, substr string) bool

Contains reports whether <substr> is within <str>, case-sensitively.

func ContainsAny added in v0.0.3

func ContainsAny(s, chars string) bool

ContainsAny reports whether any Unicode code points in <chars> are within <s>.

func ContainsI added in v0.0.10

func ContainsI(str, substr string) bool

ContainsI reports whether substr is within str, case-insensitively.

func Count added in v0.0.3

func Count(s, substr string) int

Count 统计substr在字符串s中出现的次数

func CountChars added in v0.0.10

func CountChars(str string, noSpace ...bool) map[string]int

CountChars 计算字符出现的次数,并以数组返回

func CountI added in v0.0.10

func CountI(s, substr string) int

CountI 不区分大小写统计substr在字符串s中出现的次数

func CountWords added in v0.0.10

func CountWords(str string) map[string]int

CountWords 计算单词出现的次数,并以数组返回

func DelimitedCase added in v0.1.9

func DelimitedCase(s string, del uint8) string

DelimitedCase converts a string to snake.case.delimited. Deprecated, use CaseDelimited instead.

func DelimitedScreamingCase added in v0.1.9

func DelimitedScreamingCase(s string, del uint8, screaming bool) string

DelimitedScreamingCase converts a string to DELIMITED.SCREAMING.CASE or delimited.screaming.case. Deprecated, use CaseDelimitedScreaming instead.

func Equal added in v0.0.10

func Equal(a, b string) bool

Equal 使用 UTF-8 格式比较字符串是否相等

func Explode added in v0.0.10

func Explode(delimiter, str string) []string

Explode 分割字符串

func Fields added in v0.0.10

func Fields(str string) []string

Fields 将字符串使用的单词作为切片数组返回

func HasPrefix added in v0.0.10

func HasPrefix(s, prefix string) bool

HasPrefix 测试字符串s是否以prefix开头。

func HasSuffix added in v0.0.10

func HasSuffix(s, suffix string) bool

HasSuffix 测试字符串s是否以suffix结尾

func HideStr added in v0.0.10

func HideStr(str string, percent int, hide string) string

HideStr replaces part of the the string <str> to <hide> by <percentage> from the <middle>. It considers parameter <str> as unicode string.

func Implode added in v0.0.10

func Implode(glue string, pieces []string) string

Implode 连接字符

func InArray added in v0.0.10

func InArray(a []string, s string) bool

InArray 判断字符串s是否在字符串数组a中

func IsLetterLower added in v0.0.10

func IsLetterLower(b byte) bool

IsLetterLower 是否是小写字符

func IsLetterUpper added in v0.0.10

func IsLetterUpper(b byte) bool

IsLetterUpper 是否是大写字符

func IsNumeric added in v0.0.3

func IsNumeric(s string) bool

IsNumeric 字符串是否是数字

func IsSubDomain added in v0.0.10

func IsSubDomain(subDomain string, mainDomain string) bool

IsSubDomain 检查subDomain是否为主域名mainDomain的子域名 It supports '*' in <mainDomain>.

func Join added in v0.0.10

func Join(array []string, sep string) string

Join 连接字符串

func JoinAny added in v0.0.10

func JoinAny(array interface{}, sep string) string

JoinAny 连接任何东西

func KebabCase added in v0.1.9

func KebabCase(s string) string

KebabCase converts a string to kebab-case. Deprecated, use CaseKebab instead.

func KebabScreamingCase added in v0.1.9

func KebabScreamingCase(s string) string

KebabScreamingCase converts a string to KEBAB-CASE-SCREAMING. Deprecated, use CaseKebabScreaming instead.

func LcFirst added in v0.0.10

func LcFirst(s string) string

LcFirst 首字母小写

func LenRune added in v0.0.10

func LenRune(str string) int

LenRune 返回unicode的字符串长度。

func Levenshtein added in v0.0.10

func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int

Levenshtein 计算两个字符串之间的 Levenshtein 距离 costIns: Defines the cost of insertion. costRep: Defines the cost of replacement. costDel: Defines the cost of deletion. See http://php.net/manual/en/function.levenshtein.php.

func Nl2Br added in v0.0.10

func Nl2Br(str string, isXhtml ...bool) string

Nl2Br inserts HTML line breaks(<br>|<br />) before all newlines in a string: \n\r, \r\n, \r, \n. It considers parameter <str> as unicode string.

func NumberFormat added in v0.0.10

func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string

NumberFormat 以千位分隔符方式格式化一个数字 <number>: 你要格式化的数字 <decimals>: 要保留的小数位数 <decPoint>: 指定小数点显示的字符 <thousandsSep>: 指定千位分隔符显示的字符 See http://php.net/manual/en/function.number-format.php.

func OctStr added in v0.0.10

func OctStr(str string) string

OctStr converts string container octal string to its original string, for example, to Chinese string. Eg: `\346\200\241` -> 怡

func Ord added in v0.0.10

func Ord(char string) int

Ord converts the first byte of a string to a value between 0 and 255.

func Parse added in v0.1.9

func Parse(s string) (result map[string]interface{}, err error)

Parse parses the string into map[string]interface{}.

v1=m&v2=n -> map[v1:m v2:n] v[a]=m&v[b]=n -> map[v:map[a:m b:n]] v[a][a]=m&v[a][b]=n -> map[v:map[a:map[a:m b:n]]] v[]=m&v[]=n -> map[v:[m n]] v[a][]=m&v[a][]=n -> map[v:map[a:[m n]]] v[][]=m&v[][]=n -> map[v:[map[]]] // Currently does not support nested slice. v=m&v[a]=n -> error a .[[b=c -> map[a___[b:c]

func Pos added in v0.0.10

func Pos(haystack, needle string, startOffset ...int) int

Pos 从返回中第一次出现的位置,区分大小写。如果没有找到,则返回-1。

func PosI added in v0.0.10

func PosI(haystack, needle string, startOffset ...int) int

PosI 不区分大小写返回中第一次出现的位置,区分大小写。如果没有找到,则返回-1。

func PosIRune added in v0.0.10

func PosIRune(haystack, needle string, startOffset ...int) int

PosIRune 不区分大小写查找unicode格式的字符串,返回第一次出现的位置,未找到返回-1

func PosR added in v0.0.10

func PosR(haystack, needle string, startOffset ...int) int

PosR 返回最后一次出现的位置

func PosRI added in v0.0.10

func PosRI(haystack, needle string, startOffset ...int) int

PosRI returns the position of the last occurrence of <needle> in <haystack> from <startOffset>, case-insensitively. It returns -1, if not found.

func PosRIRune added in v0.0.10

func PosRIRune(haystack, needle string, startOffset ...int) int

PosRIRune acts like function PosRI but considers <haystack> and <needle> as unicode string.

func PosRRune added in v0.0.10

func PosRRune(haystack, needle string, startOffset ...int) int

PosRRune acts like function PosR but considers <haystack> and <needle> as unicode string.

func PosRune added in v0.0.10

func PosRune(haystack, needle string, startOffset ...int) int

PosRune 查找unicode格式的字符串,返回字符串出现的第一个位置,未找到则返回-1

func QuoteMeta added in v0.0.3

func QuoteMeta(str string, chars ...string) string

QuoteMeta 返回一个带有反斜杠字符(\)的str版本 在每个字符之前: .\+*?[^]($)

func Repeat added in v0.0.10

func Repeat(input string, multiplier int) string

Repeat 返回一个新字符串,该字符串由输入字符串的乘数副本组成。

func Replace added in v0.0.8

func Replace(origin, search, replace string, count ...int) string

Replace 替换内容 origin 原始内容 search 要查找的内容 replace 要替换的内容 count 替换次数

func ReplaceByArray added in v0.0.10

func ReplaceByArray(origin string, array []string) string

ReplaceByArray 使用数组提供要替换的字符串,替换原始字符串中的内容

func ReplaceByMap added in v0.0.10

func ReplaceByMap(origin string, replaces map[string]string) string

ReplaceByMap 使用replaces的key去origin中查找对应的串,替换成key对应的value

func ReplaceI added in v0.0.10

func ReplaceI(origin, search, replace string, count ...int) string

ReplaceI 不区分大小写替换字符串

func ReplaceIByArray added in v0.0.10

func ReplaceIByArray(origin string, array []string) string

ReplaceIByArray 不区分大小写使用数组提供要替换的字符串,替换原始字符串中的内容

func ReplaceIByMap added in v0.0.10

func ReplaceIByMap(origin string, replaces map[string]string) string

ReplaceIByMap 不区分大小写使用replaces的key去origin中查找对应的串,替换成key对应的value

func Reverse added in v0.0.10

func Reverse(str string) string

Reverse 反转字符串

func RuneLen added in v0.0.10

func RuneLen(str string) int

RuneLen 返回unicode的字符串长度。

func SearchArray added in v0.0.10

func SearchArray(a []string, s string) int

SearchArray 在字符串数组中查找字符串s

func Shuffle added in v0.0.10

func Shuffle(str string) string

Shuffle randomly shuffles a string. It considers parameter <str> as unicode string.

func SimilarText added in v0.1.9

func SimilarText(first, second string, percent *float64) int

SimilarText calculates the similarity between two strings. See http://php.net/manual/en/function.similar-text.php.

func SnakeCase added in v0.1.9

func SnakeCase(s string) string

SnakeCase converts a string to snake_case. Deprecated, use CaseSnake instead.

func SnakeFirstUpperCase added in v0.1.9

func SnakeFirstUpperCase(word string, underscore ...string) string

SnakeFirstUpperCase converts a string from RGBCodeMd5 to rgb_code_md5. The length of word should not be too long Deprecated, use CaseSnakeFirstUpper instead.

func SnakeScreamingCase added in v0.1.9

func SnakeScreamingCase(s string) string

SnakeScreamingCase converts a string to SNAKE_CASE_SCREAMING. Deprecated, use CaseSnakeScreaming instead.

func SnakeString

func SnakeString(s string) string

SnakeString converts the accepted string to a snake string (XxYy to xx_yy)

func Soundex added in v0.1.9

func Soundex(str string) string

Soundex calculates the soundex key of a string. See http://php.net/manual/en/function.soundex.php.

func Split added in v0.0.8

func Split(str, delimiter string) []string

Split 分割字符串

func SplitAndTrim

func SplitAndTrim(str, delimiter string, characterMask ...string) []string

SplitAndTrim 分割字符串并去除分割后子串的头尾指定字符

func SplitAndTrimSpace added in v0.0.10

func SplitAndTrimSpace(str, delimiter string) []string

SplitAndTrimSpace 分割字符串并去除分割后子串的头尾不可见字符

func Str added in v0.0.10

func Str(haystack string, needle string) string

Str 查找字符串的首次出现的位置 the first occurrence of <needle> to the end of <haystack>. See http://php.net/manual/en/function.strstr.php.

func StrEx added in v0.0.10

func StrEx(haystack string, needle string) string

StrEx 返回字符串的一部分,从第一次出现到结束。

func StrLimit added in v0.0.10

func StrLimit(str string, length int, suffix ...string) string

StrLimit 截取字符串指定长度,使用suffix填充

func StrLimitRune added in v0.0.10

func StrLimitRune(str string, length int, suffix ...string) string

StrLimitRune 截取unicode 字符串指定长度,使用suffix填充

func StrTill added in v0.0.10

func StrTill(haystack string, needle string) string

StrTill returns part of <haystack> string ending to and including the first occurrence of <needle> from the start of <haystack>.

func StrTillEx added in v0.0.10

func StrTillEx(haystack string, needle string) string

StrTillEx returns part of <haystack> string ending to and excluding the first occurrence of <needle> from the start of <haystack>.

func StripSlashes added in v0.0.10

func StripSlashes(str string) string

StripSlashes 去除反斜杠

func SubStr added in v0.0.10

func SubStr(str string, start int, length ...int) (substr string)

SubStr 截取字符串,类似于php的substr函数

func SubStrRune added in v0.0.10

func SubStrRune(str string, start int, length ...int) (substr string)

SubStrRune 截取unicode 字符串

func ToLower added in v0.0.10

func ToLower(s string) string

ToLower 转换成大写

func ToUpper added in v0.0.10

func ToUpper(s string) string

ToUpper 转换成小写

func Trim

func Trim(str string, characterMask ...string) string

Trim 去除字符串str两边的characterMask字符

func TrimAll added in v0.0.10

func TrimAll(str string, characterMask ...string) string

TrimAll 查处str中指定的的所有字符

func TrimLeft

func TrimLeft(str string, characterMask ...string) string

TrimLeft strips whitespace (or other characters) from the beginning of a string.

func TrimLeftStr added in v0.0.10

func TrimLeftStr(str string, cut string, count ...int) string

TrimLeftStr 去除字符串左边的字符最多count次

func TrimRight

func TrimRight(str string, characterMask ...string) string

TrimRight strips whitespace (or other characters) from the end of a string.

func TrimRightStr added in v0.0.10

func TrimRightStr(str string, cut string, count ...int) string

TrimRightStr 去除字符串右边的字符cut最多count次

func TrimStr added in v0.0.10

func TrimStr(str string, cut string, count ...int) string

TrimStr 去除字符串str两边的指定字符cut,最多去除count次

func UcFirst added in v0.0.10

func UcFirst(s string) string

UcFirst 首字母大写

func UcWords added in v0.0.10

func UcWords(str string) string

UcWords 字符串中的每个单词的首字母大写

func WordWrap added in v0.0.10

func WordWrap(str string, width int, br string) string

WordWrap 打断字符串为指定数量的字串 TODO: Enable cut parameter, see http://php.net/manual/en/function.wordwrap.php.

Types

This section is empty.

Jump to

Keyboard shortcuts

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