------------------------------------------------------------ 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) ------------------------------------------------------------