Go中常用包笔记字符串strings(四)-创新互联

Package strings

此包和bytes包十分类似,除了没有bytes.Buffer,func Equal(a, b []byte) bool ,func Runes(s []byte) []rune,以外,bytes包含的方法strings都含有,只不过各方法其中一个参数有[]byte变为string而已.但是有个独特的type Replacer:

func NewReplacer(oldnew ...string) *Replacer //构造函数,不定参数,参数格式为old1,new1,old2,new2,old3,new3......表示old1会被替换为new1,old2会被替换为new2...

创新互联公司成立于2013年,先为榆社等服务建站,榆社等地企业,进行企业商务咨询服务。为榆社企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

   func (r *Replacer) Replace(s string) string //进行替换 返回新的字符串

   func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error) //替换后并写入io.Writer

其他和bytes包类似功能的方法:

字符串和字符串的关系(逐字节比较,相等,相似,包含,出现的位置,包含次数,是否是前缀后缀)

func Compare(a, b string) int

   func EqualFold(s, t string) bool

func Contains(s, substr string) bool

func Index(s, sep string) int

func LastIndex(s, sep string) int

func Count(s, sep string) int

func HasPrefix(s, prefix string) bool

func HasSuffix(s, suffix string) bool

字符串和字符串的关系(是否包含串里任何一个rune以及在字符串中的位置)

   func ContainsAny(s, chars string) bool

   func IndexAny(s, chars string) int

func LastIndexAny(s, chars string) int

字符串和rune的关系(包含,转换)

func ContainsRune(s string, r rune) bool

func IndexFunc(s string, f func(rune) bool) int

func IndexRune(s string, r rune) int

func LastIndexFunc(s string, f func(rune) bool) int

字符数组和字节的关系(位置,)

func IndexByte(s string, c byte) int

func LastIndexByte(s string, c byte) int

操作字符串(使用空格或者符合条件的rune分割分组,将分组连接成字符串,分割,大小写转换,修剪两端,按规则修改包含的每个rune,重复,替换)

func Fields(s string) []string

func FieldsFunc(s string, f func(rune) bool) []string

func Join(a []string, sep 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 Title(s string) string

func ToLower(s string) string

func ToLowerSpecial(c unicode.SpecialCase, s string) string

func ToTitle(s string) string

func ToTitleSpecial(c unicode.SpecialCase, s string) string

func ToUpper(s string) string

func ToUpperSpecial(c unicode.SpecialCase, s 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 Map(mapping func(rune) rune, s string) string

func Repeat(s string, count int) string

func Replace(s, old, new string, n int) string

type Reader

   func NewReader(s string) *Reader

   func (r *Reader) Len() int

   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) ReadByte() (byte, error)

   func (r *Reader) ReadRune() (ch rune, size int, err error)

   func (r *Reader) Reset(s string)

   func (r *Reader) Seek(offset int64, whence int) (int64, error)

   func (r *Reader) Size() int64

   func (r *Reader) UnreadByte() error

   func (r *Reader) UnreadRune() error

   func (r *Reader) WriteTo(w io.Writer) (n int64, err error)

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页名称:Go中常用包笔记字符串strings(四)-创新互联
URL分享:http://pwwzsj.com/article/cdjcic.html