Documentation
¶
Index ¶
- func AddSlashes(str string) string
- func Addslashes(str string) string
- func ChineseToPinyin(str, split string) (ret string, err error)
- func ChkContainJP(srcStr string) bool
- func Compare(a, b string) int
- func ContactStr(str ...string) string
- func Contains(s, substr string) bool
- func ContainsAny(s, chars string) bool
- func ContainsRune(s string, r rune) bool
- func Convert(src, srcCode, tagCode string) string
- func Count(s, sep string) int
- func EqualFold(s, t string) bool
- func Explode(str, split string) []string
- func Fields(s string) []string
- func FieldsFunc(s string, f func(rune) bool) []string
- func FullWidthToHalfWidth(str string) string
- func HasChinese(str string) bool
- func HasNonChinese(str string) bool
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func Implode(strSlice []string, split string) string
- func Index(s, sep string) int
- func IndexAny(s, chars string) int
- func IndexByte(s string, c byte) int
- func IndexFunc(s string, f func(rune) bool) int
- func IndexRune(s string, r rune) int
- func IsUtf8(b []byte) string
- func Join(a []string, sep string) string
- func JoinByMyself(str []string, sep string) string
- func LastIndex(s, sep string) int
- func LastIndexAny(s, chars string) int
- func LastIndexByte(s string, c byte) int
- func LastIndexFunc(s string, f func(rune) bool) int
- func ManyContains(str string, keys ...string) bool
- func Map(mapping func(rune) rune, s string) string
- func ParseInt(s string, base int, bitSize int) (i int64, err error)
- func ParseUint(s string, base int, bitSize int) (n uint64, err error)
- func Random(n int) string
- func Random1(n int) string
- func RawUrldecode(s string) (string, error)
- func RawUrlencode(s string) string
- func RemoveChinese(str string) string
- func Repeat(s string, count int) string
- func Replace(s, old, new string, n int) string
- func ReplaceAll(s, old, new string) string
- func Split(s, sep string) []string
- func SplitAfter(s, sep string) []string
- func SplitAfterN(s, sep string, n int) []string
- func SplitN(s, sep string, n int) []string
- func StrGetLastImpStr(str, exp string) string
- func StringJoin(strs ...string) (ret string)
- func SubChineseString(str string, length int) (ret string)
- func Substr(s string, start, length int) string
- func SubstrBetween(str, s1, s2 string) string
- func Title(s string) string
- func ToBytes(from string) []byte
- func ToFloat64(from string) (float64, error)
- func ToInt(from string) (int, error)
- func ToInt64(from string) (int64, error)
- func ToLower(s string) string
- func ToLowerSpecial(c unicode.SpecialCase, s string) string
- func ToTime(str, model string) (time.Time, error)
- func ToTimeStamp(str, model string) (int, error)
- func ToTitle(s string) string
- func ToTitleSpecial(c unicode.SpecialCase, s string) string
- func ToUint64(s string) (n uint64, err error)
- func ToUpper(s string) string
- func ToUpperSpecial(c unicode.SpecialCase, s string) string
- func ToUpperSpecialAndNoNeed(str *string, noCaseStr string) string
- func Trim(s string, cutset string) string
- func TrimFunc(s string, f func(rune) bool) string
- func TrimLeft(s string, cutset string) string
- func TrimLeftFunc(s string, f func(rune) bool) string
- func TrimPrefix(s, prefix string) string
- func TrimRight(s string, cutset string) string
- func TrimRightFunc(s string, f func(rune) bool) string
- func TrimSpace(s string) string
- func TrimSuffix(s, suffix string) string
- func Urldecode(s string) (string, error)
- func Urlencode(s string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSlashes ¶
返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。 这些字符是单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)。
func ChineseToPinyin ¶
中文转拼音 Mode 介绍 InitialsInCapitals: 首字母大写, 不带音调 WithoutTone: 全小写,不带音调 Tone: 全小写带音调
func Compare ¶
* 字符串比较
用于比较两个字符串的大小,如果两个字符串相等,返回为 0。如果 a 小于 b ,返回 -_1 ,反之返回 _1 。不推荐使用这个函数,直接使用 == != > < >= <= 等一系列运算符更加直观。
func Fields ¶
Fields 用一个或多个连续的空格分隔字符串 s,返回子字符串的数组(slice)。如果字符串 s 只包含空格,则返回空列表 ([]string 的长度为 0)。其中,空格的定义是 unicode.IsSpace,之前已经介绍过。 常见间隔符包括:'\t', '\n', '\v', '\f', '\r', ' ', U+0085 (NEL), U+00A0 (NBSP)
func FieldsFunc ¶
FieldsFunc 用这样的 Unicode 代码点 c 进行分隔:满足 f(c) 返回 true。该函数返回[]string。如果字符串 s 中所有的代码点 (unicode code points) 都满足 f(c) 或者 s 是空,则 FieldsFunc 返回空 slice。
func LastIndexAny ¶
func LastIndexByte ¶
func Map ¶
* 字符替换
Map 函数,将 s 的每一个字符按照 mapping 的规则做映射替换,如果 mapping 返回值 <0 ,则舍弃该字符。该方法只能对每一个字符做处理,但处理方式很灵活,可以方便的过滤,筛选汉字等。
func ParseInt ¶
* 参数 base 代表字符串按照给定的进制进行解释。一般的,base 的取值为 2~36,如果 base 的值为 0,则会根据字符串的前缀来确定 base 的值:"0x" 表示 16 进制; "0" 表示 8 进制;否则就是 10 进制。
参数 bitSize 表示的是整数取值范围,或者说整数的具体类型。取值 0、8、16、32 和 64 分别代表 int、int8、int16、int32 和 int64。
这里有必要说一下,当 bitSize==0 时的情况。
Go 中,int/uint 类型,不同系统能表示的范围是不一样的,目前的实现是,32 位系统占 4 个字节;64 位系统占 8 个字节。当 bitSize==0 时,应该表示 32 位还是 64 位呢?这里没有利用 runtime.GOARCH 之类的方式,而是巧妙的通过如下表达式确定 intSize:
const intSize = 32 << uint(^uint(0)>>63) const IntSize = intSize // number of bits in int, uint (32 or 64) 主要是 ^uint(0)>>63 这个表达式。操作符 ^ 在这里是一元操作符 按位取反,而不是 按位异或。更多解释可以参考:Go 位运算:取反和异或。
func RawUrldecode ¶
Rawurldecode - Decodes Raw-URL-encoded string
func Replace ¶
* 字符串子串替换 进行字符串替换时,考虑到性能问题,能不用正则尽量别用,应该用这里的函数。 如果我们希望一次替换多个,比如我们希望替换 This is <b>HTML</b> 中的 < 和 > 为 < 和 >,可以调用上面的函数两次。但标准库提供了另外的方法进行这种替换。
用 new 替换 s 中的 old,一共替换 n 个。 如果 n < 0,则不限制替换次数,即全部替换
func ReplaceAll ¶
该函数内部直接调用了函数 Replace(s, old, new , -_1)
func Split ¶
这四个函数都是通过 sep 进行分割,返回[]string。如果 sep 为空,相当于分成一个个的 UTF-8 字符,如 Split("abc",""),得到的是[a b c]。 Split(s, sep) 和 SplitN(s, sep, -_1) 等价;SplitAfter(s, sep) 和 SplitAfterN(s, sep, -_1) 等价。 Split 会将 s 中的 sep 去掉,而 SplitAfter 会保留 sep。 带 N 的方法可以通过最后一个参数 n 控制返回的结果中的 slice 中的元素个数,当 n < 0 时,返回所有的子字符串;当 n == 0 时,返回的结果是 nil;当 n > 0 时,表示返回的 slice 中最多只有 n 个元素,其中,最后一个元素不会分割,比如:
func SplitAfter ¶
func SplitAfterN ¶
func StrGetLastImpStr ¶
截取字符串 获取最后一份字符串 例如 /a/b/c/de/f 获取f
func SubstrBetween ¶
SubstrBetween ./abc/asd.txt 我需要 abc 截取两个字符串中间的字符串
func ToLower ¶
* 大小写转换 ToLower,ToUpper 用于大小写转换。 ToLowerSpecial,ToUpperSpecial 可以转换特殊字符的大小写 汉字拼音有效 汉字无效
func ToLowerSpecial ¶
func ToLowerSpecial(c unicode.SpecialCase, s string) string
func ToTitleSpecial ¶
func ToTitleSpecial(c unicode.SpecialCase, s string) string
将 s 的每个字母大写,并且会将一些特殊字母转换为其对应的特殊大写字母
func ToUpperSpecial ¶
func ToUpperSpecial(c unicode.SpecialCase, s string) string
func ToUpperSpecialAndNoNeed ¶
字符串转换为大写, 不需要转换的字符或者字符串不转化
func TrimPrefix ¶
如果 s 的前缀为 prefix 则返回去掉前缀后的 string , 否则 s 没有变化。
func TrimSuffix ¶
如果 s 的后缀为 suffix 则返回去掉后缀后的 string , 否则 s 没有变化。
Types ¶
This section is empty.