Documentation ¶
Overview ¶
Copyright 2020 stringsx Author(https://github.com/yudeguang/stringsx). All Rights Reserved.
This Source Code Form is subject to the terms of the MIT License. If a copy of the MIT was not distributed with this file, You can obtain one at https://github.com/yudeguang/stringsx. 字符串处理包,对标准库字符串的补充
Copyright 2020 stringsx Author(https://github.com/yudeguang/stringsx). All Rights Reserved.
This Source Code Form is subject to the terms of the MIT License. If a copy of the MIT was not distributed with this file, You can obtain one at https://github.com/yudeguang/stringsx. 字符串处理包,对标准库字符串的补充
Copyright 2020 stringsx Author(https://github.com/yudeguang/stringsx). All Rights Reserved.
This Source Code Form is subject to the terms of the MIT License. If a copy of the MIT was not distributed with this file, You can obtain one at https://github.com/yudeguang/stringsx.
Index ¶
- Constants
- func After(s, sep string) string
- func AfterLast(s, sep string) string
- func AfterNSep(s, sep string, nTimes int) string
- func Before(s, sep string) string
- func BeforeLast(s, sep string) string
- func BeforeNSep(s, sep string, nTimes int) string
- func Between(s, begin, end string) string
- func CRC32(str string) uint32
- func CenterPad(s string, length int, pad string) string
- func CommaNumbersLettersLeft(s string) string
- func ContainsHan(s string) bool
- func FmtHTML(s string) string
- func GB18030ToUTF8(s string) string
- func GB2312ToUTF8(s string) string
- func GBKToUTF8(s string) string
- func HanLeft(s string) string
- func IsLetter(s string) bool
- func IsLetterLower(b byte) bool
- func IsLetterUpper(b byte) bool
- func IsNumber(s string) bool
- func JoinInterface(sep string, elems ...interface{}) string
- func JoinInts(sep string, elems ...int) string
- func JoinStrings(sep string, args ...string) string
- func Left(s string, n int) string
- func LeftPad(s string, length int, pad string) string
- func LeftRightPad(s string, length int, pad string) string
- func LettersLeft(s string) string
- func MD5(str string) string
- func MostSimilar(a string, b []string) string
- func MostSimilarWithScore(a string, b []string) *similarity.Match
- func MostSimilars(a string, b []string) []string
- func NumbersLeft(s string) string
- func NumbersLettersLeft(s string) string
- func Rand(s string) string
- func RelevantCharactersLeft(s, RelevantCharacter string) string
- func RemoveHan(s string) string
- func Reverse(s string) string
- func Right(s string, n int) string
- func Rightpad(s string, length int, pad string) string
- func RuneIsHan(r rune) bool
- func SHA1(str string) string
- func SplitByLen(s string, sepLen int) []string
- func UTF8ToGB18030(s string) string
- func UTF8ToGB2312(s string) string
- func UTF8ToGBK(s string) string
- type Charset
Constants ¶
const ( UTF8 = Charset("UTF-8") GB18030 = Charset("GB18030") GBK = Charset("GBK") GB2312 = Charset("HZGB2312") )
Variables ¶
This section is empty.
Functions ¶
func CommaNumbersLettersLeft ¶
只保留逗号以及数字和英文字母,因为逗号一般用于分隔文本
func GB18030ToUTF8 ¶
GB18030转换为UTF8,应优先使用GB18030,GB18030为GBK的超集,GBK又为GB2312的超集
func JoinInterface ¶
用分隔符sep把若干个字符或int,double等类型数据拼接在一起,实际为strings.Join的变体形式
func JoinInterface(sep string, args ...interface{}) string { l := len(args) switch l { case 0: return "" case 1: return fmt.Sprint(args[0]) case 2: return fmt.Sprint(args[0]) + sep + fmt.Sprint(args[1]) case 3: return fmt.Sprint(args[0]) + sep + fmt.Sprint(args[1]) + sep + fmt.Sprint(args[2]) } var buffer bytes.Buffer //前面若干条中间要加sep for i := 0; i < l-1; i++ { buffer.WriteString(fmt.Sprint(args[i]) + sep) } //最后次不加sep buffer.WriteString(fmt.Sprint(args[l-1])) return buffer.String() }
func JoinStrings ¶
用分隔符sep把若干个字符拼接在一起,实际为strings.Join的变体形式
func LeftPad ¶
返回字符串str,左面用字符串padstr填补直到str是len个字符长,,此函数与mysql中LPAD()行为保持一致 LeftPad("hello", 4, " ") => "hello" LeftPad("hello", 10, " ") => " hello" LeftPad("hello", 10, "123") => "12312hello"
func LeftRightPad ¶
返回两侧字符按一定规则替换后的字符串接 LeftRightPad("hello", 4, " ") => "hell" LeftRightPad("hello", 10, " ") => " hello " LeftRightPad("hello", 10, "123") => "12hello123"
func MostSimilar ¶
返回最相似的一个字符串,前缀匹配优先 用于特定的项目 如果一点相似度都没有,则返回空
func MostSimilarWithScore ¶
func MostSimilarWithScore(a string, b []string) *similarity.Match
返回相似度最高的那个字符串 并且带匹配度 此为通用算法
func RelevantCharactersLeft ¶
保留输入的相关字符