annuaire recherche
archive archive/tar archive/zip bufio bufio(缓存) builtin builtin(内置包) bytes bytes(包字节) compress compress/bzip2(压缩/bzip2) compress/flate(压缩/flate) compress/gzip(压缩/gzip) compress/lzw(压缩/lzw) compress/zlib(压缩/zlib) container container/heap(容器数据结构heap) container/list(容器数据结构list) container/ring(容器数据结构ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(数据库/sql) database/sql/driver(数据库/sql/driver) debug debug/dwarf(调试/dwarf) debug/elf(调试/elf) debug/gosym(调试/gosym) debug/macho(调试/macho) debug/pe(调试/pe) debug/plan9obj(调试/plan9obj) encoding encoding(编码) encoding/ascii85(编码/ascii85) encoding/asn1(编码/asn1) encoding/base32(编码/base32) encoding/base64(编码/base64) encoding/binary(编码/binary) encoding/csv(编码/csv) encoding/gob(编码/gob) encoding/hex(编码/hex) encoding/json(编码/json) encoding/pem(编码/pem) encoding/xml(编码/xml) errors errors(错误) expvar expvar flag flag(命令行参数解析flag包) fmt fmt go go/ast(抽象语法树) go/build go/constant(常量) go/doc(文档) go/format(格式) go/importer go/parser go/printer go/scanner(扫描仪) go/token(令牌) go/types(类型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(图像) image/color(颜色) image/color/palette(调色板) image/draw(绘图) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系统) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路径) plugin plugin(插件) reflect reflect(反射) regexp regexp(正则表达式) regexp/syntax runtime runtime(运行时) runtime/debug(调试) runtime/internal/sys runtime/pprof runtime/race(竞争) runtime/trace(执行追踪器) sort sort(排序算法) strconv strconv(转换) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系统调用) testing testing(测试) testing/iotest testing/quick text text/scanner(扫描文本) text/tabwriter text/template(定义模板) text/template/parse time time(时间戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
personnages

  • import "strings"

  • 概观

  • 索引

  • 示例

概观

打包字符串实现简单的函数来操纵 UTF-8 编码的字符串。

索引

  • func Compare(a, b string) int

  • func Contains(s, substr string) bool

  • func ContainsAny(s, chars string) bool

  • func ContainsRune(s string, r rune) bool

  • func Count(s, substr string) int

  • func EqualFold(s, t string) bool

  • func Fields(s string) []string

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

  • func HasPrefix(s, prefix string) bool

  • func HasSuffix(s, suffix string) bool

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

  • func LastIndex(s, substr 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 Map(mapping func(rune) rune, s string) string

  • func Repeat(s string, count int) string

  • func Replace(s, old, new string, n int) 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

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

  • type Replacer

  • func NewReplacer(oldnew ...string) *Replacer

  • func (r *Replacer) Replace(s string) string

  • func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)

  • 错误

示例

Compare Contains ContainsAny ContainsRune Count EqualFold Fields FieldsFunc HasPrefix HasSuffix Index IndexAny IndexByte IndexFunc IndexRune Join LastIndex LastIndexAny Map NewReplacer Repeat Replace Split SplitAfter SplitAfterN SplitN Title ToLower ToTitle ToUpper Trim TrimFunc TrimPrefix TrimSpace TrimSuffix

打包files

compare.go reader.go replace.go search.go strings.go strings_amd64.go strings_decl.go

func Compare

func Compare(a, b string) int

Compare 按字典顺序返回一个比较两个字符串的整数。如果 a == b,结果将为0,如果 a <b 则返回-1,如果 a> b 则返回+1。

Compare 仅包含与封装字节的对称性。使用内置的字符串比较运算符 ==,<,> 等通常会更清晰并且速度更快。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.Compare("a", "b"))
	fmt.Println(strings.Compare("a", "a"))
	fmt.Println(strings.Compare("b", "a"))}

func Contains

func Contains(s, substr string) bool

包含报告 substr 是否在 s 之内。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.Contains("seafood", "foo"))
	fmt.Println(strings.Contains("seafood", "bar"))
	fmt.Println(strings.Contains("seafood", ""))
	fmt.Println(strings.Contains("", ""))}

func ContainsAny

func ContainsAny(s, chars string) bool

ContainsAny 报告字符中的任何 Unicode 代码点是否在 s 中。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.ContainsAny("team", "i"))
	fmt.Println(strings.ContainsAny("failure", "u & i"))
	fmt.Println(strings.ContainsAny("foo", ""))
	fmt.Println(strings.ContainsAny("", ""))}

func ContainsRune

func ContainsRune(s string, r rune) bool

ContainsRune 报告 Unicode 代码点 r 是否在 s 内。

示例

package mainimport ("fmt""strings")func main() {// Finds whether a string contains a particular Unicode code point.// The code point for the lowercase letter "a", for example, is 97.
	fmt.Println(strings.ContainsRune("aardvark", 97))
	fmt.Println(strings.ContainsRune("timeout", 97))}

func Count

func Count(s, substr string) int

Count 计算 s 中不重叠的 substr 实例的数量。如果 substr 是一个空字符串,则 Count 将返回 1 + s 中的 Unicode 代码点数。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.Count("cheese", "e"))
	fmt.Println(strings.Count("five", "")) // before & after each rune}

func EqualFold

func EqualFold(s, t string) bool

EqualFold 报告 s 和 t,解释为 UTF-8 字符串,在 Unicode 大小写折叠下是否相等。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.EqualFold("Go", "go"))}

func Fields

func Fields(s string) []string

Fields 将字符串 s 分割为一个或多个连续的空格字符的每个实例,由 unicode.IsSpace 定义,如果 s 仅包含空格,则返回 s 的子字符串数组或空列表。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Printf("Fields are: %q", strings.Fields("  foo bar  baz   "))}

func FieldsFunc

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

FieldsFunc 在每次运行满足 f(c) 的 Unicode 代码点 c 时分割字符串 s ,并返回一组 s 片段。如果 s 中的所有代码点都满足 f(c) 或者字符串为空,则返回空片。FieldsFunc 不保证它调用 f(c) 的顺序。如果f没有为给定的c返回一致的结果,那么 FieldsFunc 可能会崩溃。

示例

package mainimport ("fmt""strings""unicode")func main() {
	f := func(c rune) bool {return !unicode.IsLetter(c) && !unicode.IsNumber(c)}
	fmt.Printf("Fields are: %q", strings.FieldsFunc("  foo1;bar2,baz3...", f))}

func HasPrefix

func HasPrefix(s, prefix string) bool

HasPrefix 测试字符串 s 是否以前缀开头。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.HasPrefix("Gopher", "Go"))
	fmt.Println(strings.HasPrefix("Gopher", "C"))
	fmt.Println(strings.HasPrefix("Gopher", ""))}

func HasSuffix

func HasSuffix(s, suffix string) bool

HasSuffix 测试字符串 s 是否以后缀结尾。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.HasSuffix("Amigo", "go"))
	fmt.Println(strings.HasSuffix("Amigo", "O"))
	fmt.Println(strings.HasSuffix("Amigo", "Ami"))
	fmt.Println(strings.HasSuffix("Amigo", ""))}

func Index

func Index(s, substr string) int

索引返回 s 中第一个 substr 实例的索引,如果 substr 不存在于 s 中,则返回-1。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.Index("chicken", "ken"))
	fmt.Println(strings.Index("chicken", "dmr"))}

func IndexAny

func IndexAny(s, chars string) int

IndexAny 返回 s 中任何 Unicode 代码点的第一个实例的索引,如果没有来自 chars 的 Unicode 代码点,则返回-1。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.IndexAny("chicken", "aeiouy"))
	fmt.Println(strings.IndexAny("crwth", "aeiouy"))}

func IndexByte

func IndexByte(s string, c byte) int

IndexByte 返回 s 的第一个实例的索引,如果 c 不存在于 s 中,则返回-1。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.IndexByte("golang", 'g'))
	fmt.Println(strings.IndexByte("gophers", 'h'))
	fmt.Println(strings.IndexByte("golang", 'x'))}

func IndexFunc

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

IndexFunc 将索引返回到满足 f(c) 的第一个 Unicode 代码点的 s 中,否则返回-1。

示例

package mainimport ("fmt""strings""unicode")func main() {
	f := func(c rune) bool {return unicode.Is(unicode.Han, c)}
	fmt.Println(strings.IndexFunc("Hello, 世界", f))
	fmt.Println(strings.IndexFunc("Hello, world", f))}

func IndexRune

func IndexRune(s string, r rune) int

IndexRune 返回 Unicode 代码点 r 的第一个实例的索引,如果符号不存在于 s 中,则返回-1。如果 r 是 utf8.RuneError ,它将返回任何无效的 UTF-8 字节序列的第一个实例。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.IndexRune("chicken", 'k'))
	fmt.Println(strings.IndexRune("chicken", 'd'))}

func Join

func Join(a []string, sep string) string

Join 连接 a 的元素以创建单个字符串。分隔符字符串 sep 放置在结果字符串中的元素之间。

示例

package mainimport ("fmt""strings")func main() {
	s := []string{"foo", "bar", "baz"}
	fmt.Println(strings.Join(s, ", "))}

func LastIndex

func LastIndex(s, substr string) int

LastIndex 返回 s 中最后一个 substr 实例的索引,如果 substr 不存在于 s 中,则返回-1。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.Index("go gopher", "go"))
	fmt.Println(strings.LastIndex("go gopher", "go"))
	fmt.Println(strings.LastIndex("go gopher", "rodent"))}

func LastIndexAny

func LastIndexAny(s, chars string) int

LastIndexAny 返回来自 s 中字符的任何 Unicode 代码点的最后一个实例的索引,如果没有来自 chars 的 Unicode 代码点存在于 s 中,则返回-1。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.LastIndexAny("go gopher", "go"))
	fmt.Println(strings.LastIndexAny("go gopher", "rodent"))
	fmt.Println(strings.LastIndexAny("go gopher", "fail"))}

func LastIndexByte

func LastIndexByte(s string, c byte) int

LastIndexByte 返回 s 的最后一个实例的索引,如果 c 不存在于 s 中,则返回-1。

func LastIndexFunc

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

LastIndexFunc 将索引返回到满足 f(c) 的最后一个 Unicode 代码点的 s 中,否则返回-1。

func Map

func Map(mapping func(rune) rune, s string) string

Map 根据映射函数返回字符串 s 的一个副本,并修改其所有字符。如果映射返回负值,则字符将从字符串中删除而不会被替换。

示例

package mainimport ("fmt""strings")func main() {
	rot13 := func(r rune) rune {switch {case r >= 'A' && r <= 'Z':return 'A' + (r-'A'+13)%26case r >= 'a' && r <= 'z':return 'a' + (r-'a'+13)%26}return r}
	fmt.Println(strings.Map(rot13, "'Twas brillig and the slithy gopher..."))}

func Repeat

func Repeat(s string, count int) string

Repeat 返回一个由字符串 s 的计数副本组成的新字符串。

如果count为负数或(len(s)* count)的结果溢出,它会发生混乱。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println("ba" + strings.Repeat("na", 2))}

func Replace

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

Replace 返回字符串s的一个副本,其中前 n 个不重叠的旧实例由 new 替换。如果 old 为空,则它在字符串的开始处和每个 UTF-8 序列之后进行匹配,最多生成一个 k-1 字符串的 k+1 替换。如果 n <0,则替换次数没有限制。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2))
	fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1))}

func Split

func Split(s, sep string) []string

将切片分割成由 sep 分隔的所有子字符串,并在这些分隔符之间返回一个子切片片段。

如果 s 不包含 sep 且 sep 不为空,则 Split 将返回长度为1的片段,其唯一元素为 s。

如果 sep 为空,Split 会在每个 UTF-8 序列之后分裂。如果 s 和 sep 都为空,Split 将返回一个空片。

它相当于 SplitN,计数为-1。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Printf("%q\n", strings.Split("a,b,c", ","))
	fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a "))
	fmt.Printf("%q\n", strings.Split(" xyz ", ""))
	fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))}

func SplitAfter

func SplitAfter(s, sep string) []string

SplitAfter 在每个 sep 实例之后切片到所有子字符串中,并返回这些子字符串的一部分。

如果 s 不包含 sep 且 sep 不为空,则 SplitAfter 将返回长度为1的片段,其唯一元素为 s。

如果 sep 为空,则 SplitAfter 会在每个 UTF-8 序列后分割。如果 s 和 sep 均为空,则 SplitAfter 将返回空片。

它相当于 SplitAfterN,计数为-1。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Printf("%q\n", strings.SplitAfter("a,b,c", ","))}

func SplitAfterN

func SplitAfterN(s, sep string, n int) []string

在每个 sep 实例之后,SplitAfterN 将 s 切成子字符串,并返回这些子字符串的一部分。

计数决定要返回的子字符串的数量:

n > 0: at most n substrings; the last substring will be the unsplit remainder.n == 0: the result is nil (zero substrings)n < 0: all substrings

s 和 sep 的边缘情况(例如,空字符串)按照 SplitAfter 文档中的描述进行处理。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", 2))}

func SplitN

func SplitN(s, sep string, n int) []string

将 SplitN 切片分割成由 sep 分隔的子字符串,并返回这些分隔符之间的一个子字符串片段。

计数决定要返回的子字符串的数量:

n > 0: at most n substrings; the last substring will be the unsplit remainder.n == 0: the result is nil (zero substrings)n < 0: all substrings

s 和 sep 的边缘情况(例如,空字符串)按照 Split 的文档中的描述进行处理。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Printf("%q\n", strings.SplitN("a,b,c", ",", 2))
	z := strings.SplitN("a,b,c", ",", 0)
	fmt.Printf("%q (nil = %v)\n", z, z == nil)}

func Title

func Title(s string) string

标题返回字符串 s 的一个副本,其中所有的 Unicode 字母开始将单词映射到其标题大小写。

BUG(rsc):规则标题用于单词边界的规则不能正确处理 Unicode 标点符号。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.Title("her royal highness"))}

func ToLower

func ToLower(s string) string

ToLower 返回字符串 s 的一个副本,其中所有 Unicode 字母映射为小写字母。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.ToLower("Gopher"))}

func ToLowerSpecial

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

ToLowerSpecial 返回字符串 s 的一个副本,其中所有的 Unicode 字母都映射到它们的小写字母,优先考虑特殊的外壳规则。

func ToTitle

func ToTitle(s string) string

ToTitle 返回字符串 s 的一个副本,其中所有 Unicode 字母映射到它们的标题大小写。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.ToTitle("loud noises"))
	fmt.Println(strings.ToTitle("хлеб"))}

func ToTitleSpecial

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

ToTitleSpecial 返回字符串 s 的副本,其中所有的 Unicode 字母映射到它们的标题大小写,优先考虑特殊的外壳规则。

func ToUpper

func ToUpper(s string) string

ToUpper 返回字符串 s 的副本,其中所有的 Unicode 字母都映射为大写字母。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.ToUpper("Gopher"))}

func ToUpperSpecial

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

ToUpperSpecial 返回字符串 s 的副本,其中所有的 Unicode 字母映射为大写字母,优先考虑特殊的外壳规则。

func Trim

func Trim(s string, cutset string) string

Trim 将返回字符串 s 的一部分,并将 cutset 中包含的所有前导和尾部 Unicode 代码点删除。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Printf("[%q]", strings.Trim(" !!! Achtung! Achtung! !!! ", "! "))}

func TrimFunc

func TrimFunc(s string, f func(rune) bool) string

TrimFunc 返回字符串 s 的一个片段,其中所有前导和尾随 Unicode 代码点 c 都满足 f(c)。

示例

package mainimport ("fmt""strings""unicode")func main() {
	f := func(c rune) bool {return !unicode.IsLetter(c) && !unicode.IsNumber(c)}
	fmt.Printf("[%q]", strings.TrimFunc("  Achtung1! Achtung2,...", f))}

func TrimLeft

func TrimLeft(s string, cutset string) string

TrimLeft 返回 cutset 中包含的所有前导 Unicode 代码点被删除的字符串 s 的一部分。

func TrimLeftFunc

func TrimLeftFunc(s string, f func(rune) bool) string

TrimLeftFunc 返回字符串 s 的一部分,其中所有前导 Unicode 代码点 c 满足 f(c)。

func TrimPrefix

func TrimPrefix(s, prefix string) string

TrimPrefix 在没有提供的前导前缀字符串的情况下返回 s。如果 s 不是以前缀开始,则 s 不变。

示例

package mainimport ("fmt""strings")func main() {var s = "Goodbye,, world!"
	s = strings.TrimPrefix(s, "Goodbye,")
	s = strings.TrimPrefix(s, "Howdy,")
	fmt.Print("Hello" + s)}

func TrimRight

func TrimRight(s string, cutset string) string

TrimRight 返回字符串 s 的一部分,删除 cutset 中包含的所有尾部 Unicode 代码点。

func TrimRightFunc

func TrimRightFunc(s string, f func(rune) bool) string

TrimRightFunc 返回字符串 s 的一个片段,其中所有的尾随 Unicode 代码点 c 满足 f(c) 。

func TrimSpace

func TrimSpace(s string) string

TrimSpace 返回字符串 s 的一部分,删除所有前导和尾部空白,如 Unicode 定义的。

示例

package mainimport ("fmt""strings")func main() {
	fmt.Println(strings.TrimSpace(" \t\n a lone gopher \n\t\r\n"))}

func TrimSuffix

func TrimSuffix(s, suffix string) string

TrimSuffix 在没有提供尾随后缀字符串的情况下返回 s。如果 s 不以后缀结尾,则 s 不变。

示例

package mainimport ("fmt""strings")func main() {var s = "Hello, goodbye, etc!"
	s = strings.TrimSuffix(s, "goodbye, etc!")
	s = strings.TrimSuffix(s, "planet")
	fmt.Print(s, "world!")}

键入Reader

Reader 通过读取字符串来实现 io.Reader,io.ReaderAt,io.Seeker,io.WriterTo,io.ByteScanner 和 io.RuneScanner 接口。

type Reader struct {        // contains filtered or unexported fields}

func NewReader

func NewReader(s string) *Reader

NewReader 从 s 中返回一个新的 Reader 读数。它与 bytes.NewBufferString 类似,但更高效且只读。

func (*Reader) Len

func (r *Reader) Len() int

Len 返回字符串未读部分的字节数。

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

func (*Reader) ReadAt

func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

func (*Reader) ReadRune

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

func (*Reader) Reset

func (r *Reader) Reset(s string)

重置将读取器重置为从 s 读取。

func (*Reader) Seek

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

Seek 实现了 io.Seeker 接口。

func (*Reader) Size

func (r *Reader) Size() int64

Size 返回基础字符串的原始长度。Size 是可通过 ReadAt 读取的字节数。返回的值总是相同的,不受调用任何其他方法的影响。

func (*Reader) UnreadByte

func (r *Reader) UnreadByte() error

func (*Reader) UnreadRune

func (r *Reader) UnreadRune() error

func (*Reader) WriteTo

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

WriteTo 实现 io.WriterTo 接口。

键入Replacer

Replacer 用替换替换字符串列表。由多个 goroutines 并行使用是安全的。

type Replacer struct {        // contains filtered or unexported fields}

func NewReplacer

func NewReplacer(oldnew ...string) *Replacer

NewReplacer 从旧的新的字符串对列表中返回一个新的 Replacer。按顺序执行替换,不会有重叠匹配。

示例

package mainimport ("fmt""strings")func main() {
	r := strings.NewReplacer("<", "&lt;", ">", "&gt;")
	fmt.Println(r.Replace("This is <b>HTML</b>!"))}

func (*Replacer) Replace

func (r *Replacer) Replace(s string) string

Replace 返回执行所有替换的s的副本。

func (*Replacer) WriteString

func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)

WriteString 将 s 写入 w 并执行所有替换。

错误

  •   标题用于单词边界的规则不能正确处理 Unicode 标点符号。

Article précédent: Article suivant: