Documentation ¶
Overview ¶
Package gstr provides functions for string handling.
字符串处理.
Index ¶
- func AddSlashes(str string) string
- func Chr(ascii int) string
- func ChunkSplit(body string, chunkLen int, end string) string
- func Compare(a, b string) int
- func Contains(str, substr string) bool
- func ContainsAny(s, chars string) bool
- func ContainsI(str, substr string) bool
- func CountChars(str string, noSpace ...bool) map[string]int
- func CountWords(str string) map[string]int
- func Equal(a, b string) bool
- func Explode(delimiter, str string) []string
- func Fields(str string) []string
- func HideStr(str string, percent int, hide string) string
- func Implode(glue string, pieces []string) string
- func InArray(a []string, s string) bool
- func IsLetterLower(b byte) bool
- func IsLetterUpper(b byte) bool
- func IsNumeric(s string) bool
- func Join(array []string, sep string) string
- func LcFirst(s string) string
- func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int
- func Nl2Br(str string, isXhtml ...bool) string
- func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string
- func Ord(char string) int
- func Parse(encodedString string, result map[string]interface{}) error
- func Pos(haystack, needle string, startOffset ...int) int
- func PosI(haystack, needle string, startOffset ...int) int
- func PosR(haystack, needle string, startOffset ...int) int
- func PosRI(haystack, needle string, startOffset ...int) int
- func QuoteMeta(str string) string
- func Repeat(input string, multiplier int) string
- func Replace(origin, search, replace string, count ...int) string
- func ReplaceByMap(origin string, replaces map[string]string) string
- func Reverse(str string) string
- func RuneLen(str string) int
- func SearchArray(a []string, s string) int
- func Shuffle(str string) string
- func SimilarText(first, second string, percent *float64) int
- func Soundex(str string) string
- func Split(str, delimiter string) []string
- func Str(haystack string, needle string) string
- func StrLimit(str string, length int, suffix ...string) string
- func StripSlashes(str string) string
- func SubStr(str string, start int, length ...int) (substr string)
- func ToLower(s string) string
- func ToUpper(s string) string
- func Trim(str string, characterMask ...string) string
- func TrimLeft(str string, characterMask ...string) string
- func TrimLeftStr(str string, cut string) string
- func TrimRight(str string, characterMask ...string) string
- func TrimRightStr(str string, cut string) string
- func UcFirst(s string) string
- func UcWords(str string) string
- func WordWrap(str string, width int, br string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChunkSplit ¶
Split a string into smaller chunks. Can be used to split a string into smaller chunks which is useful for e.g. converting BASE64 string output to match RFC 2045 semantics. It inserts end every chunkLen characters.
将字符串分割成小块。使用此函数将字符串分割成小块非常有用。 例如将BASE64的输出转换成符合RFC2045语义的字符串。 它会在每 chunkLen 个字符后边插入 end。
func Compare ¶
Compare returns an integer comparing two strings lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
比较两个字符串。
func ContainsAny ¶
ContainsAny reports whether any Unicode code points in chars are within s.
判断是否s中是否包含chars指定的任意字符。
func ContainsI ¶
Contains reports whether substr is within str, case-insensitive.
判断是否substr存在于str中(不区分大小写)。
func Equal ¶
Equal reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, case-insensitive.
比较两个字符串是否相等(不区分大小写)。
func Explode ¶
Split a string by a string, to an array. See http://php.net/manual/en/function.explode.php.
此函数返回由字符串组成的数组,每个元素都是 str 的一个子串,它们被字符串 delimiter 作为边界点分割出来。
func HideStr ¶
HideStr replaces part of the the string by percentage from the middle.
按照百分比从字符串中间向两边隐藏字符(主要用于姓名、手机号、邮箱地址、身份证号等的隐藏),支持utf-8中文,支持email格式。
func Implode ¶
Join array elements with a string. http://php.net/manual/en/function.implode.php
用glue将字符串数组pieces连接为一个字符串。
func Join ¶
Join concatenates the elements of a to create a single string. The separator string sep is placed between elements in the resulting string.
用sep将字符串数组array连接为一个字符串。
func LcFirst ¶
LcFirst returns a copy of the string s with the first letter mapped to its lower case.
字符串首字母转换为小写
func Levenshtein ¶
Calculate Levenshtein distance between two strings. 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.
计算两个字符串之间的编辑距离(Levenshtein distance)。
func Nl2Br ¶
Inserts HTML line breaks before all newlines in a string. \n\r, \r\n, \r, \n
在字符串 string 所有新行之前插入 '<br />' 或 '<br>',并返回。
func NumberFormat ¶
Format a number with grouped thousands. decimals: Sets the number of decimal points. decPoint: Sets the separator for the decimal point. thousandsSep: Sets the thousands separator. See http://php.net/manual/en/function.number-format.php.
以千位分隔符方式格式化一个数字.
func Ord ¶
Convert the first byte of a string to a value between 0 and 255.
解析 char 二进制值第一个字节为 0 到 255 范围的无符号整型类型。
func Parse ¶
Parses the string into variables. f1=m&f2=n -> map[f1:m f2:n] f[a]=m&f[b]=n -> map[f:map[a:m b:n]] f[a][a]=m&f[a][b]=n -> map[f:map[a:map[a:m b:n]]] f[]=m&f[]=n -> map[f:[m n]] f[a][]=m&f[a][]=n -> map[f:map[a:[m n]]] f[][]=m&f[][]=n -> map[f:[map[]]] // Currently does not support nested slice. f=m&f[a]=n -> error // This is not the same as PHP. a .[[b=c -> map[a___[b:c]
将字符串解析成Map。
func Pos ¶
Find the position of the first occurrence of a substring in a string.
返回 needle 在 haystack 中首次出现的数字位置,找不到返回-1。
func PosI ¶
Find the position of the first occurrence of a case-insensitive substring in a string.
返回在字符串 haystack 中 needle 首次出现的数字位置(不区分大小写),找不到返回-1。
func PosR ¶
Find the position of the last occurrence of a substring in a string.
查找指定字符串在目标字符串中最后一次出现的位置,找不到返回-1。
func PosRI ¶
Find the position of the last occurrence of a case-insensitive substring in a string.
以不区分大小写的方式查找指定字符串在目标字符串中最后一次出现的位置,找不到返回-1。
func QuoteMeta ¶
Returns a version of str with a backslash character (\) before every character that is among: .\+*?[^]($)
转义字符串,转义的特殊字符包括:.\+*?[^]($)。
func Repeat ¶
Repeat returns a new string consisting of multiplier copies of the string input.
按照指定大小创建重复的字符串。
func Replace ¶
Replace returns a copy of the string <origin> with string <search> replaced by <replace>.
字符串替换(大小写敏感)
func SearchArray ¶
Traverse the array to find the string index position, if not exist, return-1.
遍历数组查找字符串索引位置,如果不存在则返回-1,使用完整遍历查找.
func SimilarText ¶
Calculate the similarity between two strings. See http://php.net/manual/en/function.similar-text.php.
计算两个字符串的相似度。
func Soundex ¶
Calculate the soundex key of a string. See http://php.net/manual/en/function.soundex.php.
计算字符串的SOUNDEX值,SOUNDEX为由四个字符组成的代码以评估两个字符串的相似性。
func Split ¶
Split a string by a string, to an array.
此函数返回由字符串组成的数组,每个元素都是 str 的一个子串,它们被字符串 delimiter 作为边界点分割出来。
func Str ¶
Returns part of haystack string starting from and including the first occurrence of needle to the end of haystack. See http://php.net/manual/en/function.strstr.php.
查找字符串的首次出现。返回 haystack 字符串从 needle 第一次出现的位置开始到 haystack 结尾的字符串。
func StrLimit ¶
Returns the portion of string specified by the <length> parameters, if the length of str is greater than <length>, then the <suffix> will be appended to the result.
字符串长度截取限制,超过长度限制被截取并在字符串末尾追加指定的内容,支持中文
func SubStr ¶
Returns the portion of string specified by the start and length parameters.
字符串截取,支持中文
func ToLower ¶
ToLower returns a copy of the string s with all Unicode letters mapped to their lower case. 字符串转换为小写
func ToUpper ¶
ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case.
字符串转换为大写
func Trim ¶
Strip whitespace (or other characters) from the beginning and end of a string.
去除字符串首尾处的空白字符(或者其他字符)。
func TrimLeft ¶
Strip whitespace (or other characters) from the beginning of a string.
去除字符串首的空白字符(或者其他字符)。
func TrimLeftStr ¶
Strip all of the given <cut> string from the beginning of a string.
去除字符串首的给定字符串。
func TrimRight ¶
Strip whitespace (or other characters) from the end of a string.
去除字符串尾的空白字符(或者其他字符)。
func UcFirst ¶
UcFirst returns a copy of the string s with the first letter mapped to its upper case.
字符串首字母转换为大写
Types ¶
This section is empty.