Golang学习聽-聽strings聽包
--------------------
strings 包与 bytes 包中的函数用法基本一样,不再赘述。 只对 Replacer 进行说明。
// 转换
func聽ToUpper(s string) string
func聽ToLower(s string) string
func聽ToTitle(s string) string
func聽ToUpperSpecial(_case unicode.SpecialCase, s string) string
func聽ToLowerSpecial(_case unicode.SpecialCase, s string) string
func聽ToTitleSpecial(_case unicode.SpecialCase, s string) string
func聽Title(s string) string
--------------------
// 比较
func聽Compare(a, b string) int
func聽EqualFold(s, t string) bool
--------------------
// 清理
func聽Trim(s string, cutset string) string
func聽TrimLeft(s string, cutset string) string
func聽TrimRight(s string, cutset string) string
func聽TrimFunc(s string, f func(rune) bool) string
func聽TrimLeftFunc(s string, f func(rune) bool) string
func聽TrimRightFunc(s string, f func(rune) bool) string
func聽TrimSpace(s string) string
func聽TrimPrefix(s, prefix string) string
func聽TrimSuffix(s, suffix string) string
--------------------
// 拆合
func聽Split(s, sep string) []string
func聽SplitN(s, sep string, n int) []string
func聽SplitAfter(s, sep string) []string
func聽SplitAfterN(s, sep string, n int) []string
func聽Fields(s string) []string
func聽FieldsFunc(s string, f func(rune) bool) []string
func聽Join(a []string, sep string) string
func聽Repeat(s string, count int) string
--------------------
// 子串
func聽HasPrefix(s, prefix string) bool
func聽HasSuffix(s, suffix string) bool
func聽Contains(s, substr string) bool
func聽ContainsRune(s string, r rune) bool
func聽ContainsAny(s, chars string) bool
func聽Index(s, sep string) int
func聽IndexByte(s string, c byte) int
func聽IndexRune(s string, r rune) int
func聽IndexAny(s, chars string) int
func聽IndexFunc(s string, f func(rune) bool) int
func聽LastIndex(s, sep string) int
func聽LastIndexByte(s string, c byte) int
func聽LastIndexAny(s, chars string) int
func聽LastIndexFunc(s string, f func(rune) bool) int
func聽Count(s, sep string) int
--------------------
// 替换
func聽Replace(s, old, new string, n int) string
func聽Map(mapping func(rune) rune, s string) string
--------------------
type Reader struct { ... }
func聽NewReader(s string) *Reader
func (r *Reader) Read(b []byte) (n int, err error)
func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)
func (r *Reader) WriteTo(w io.Writer) (n int64, err error)
func (r *Reader) Seek(offset int64, whence int) (int64, error)
func (r *Reader) ReadByte() (byte, error)
func (r *Reader) UnreadByte() error
func (r *Reader) ReadRune() (ch rune, size int, err error)
func (r *Reader) UnreadRune() error
func (r *Reader) Len() int
func (r *Reader) Size() int64
func (r *Reader) Reset(s string)
--------------------
type Replacer struct { ... }
// 创建一个替换规则,参数为“查找内容”和“替换内容”的交替形式。
// 替换操作会依次将第 1 个字符串替换为第 2 个字符串,将第 3 个字符串
// 替换为第 4 个字符串,以此类推。
// 替换规则可以同时被多个例程使用。
func聽NewReplacer(oldnew ...string) *Replacer
// 使用替换规则对 s 进行替换并返回结果。
func (r *Replacer) Replace(s string) string
// 使用替换规则对 s 进行替换并将结果写入 w。
// 返回写入的字节数和遇到的错误。
func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)
有疑问加站长微信联系(非本文作者)