summaryrefslogtreecommitdiff
path: root/devdocs/go/strings%2Findex.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/go/strings%2Findex.html')
-rw-r--r--devdocs/go/strings%2Findex.html488
1 files changed, 488 insertions, 0 deletions
diff --git a/devdocs/go/strings%2Findex.html b/devdocs/go/strings%2Findex.html
new file mode 100644
index 00000000..53dc7feb
--- /dev/null
+++ b/devdocs/go/strings%2Findex.html
@@ -0,0 +1,488 @@
+<h1> Package strings </h1> <ul id="short-nav">
+<li><code>import "strings"</code></li>
+<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
+<li><a href="#pkg-index" class="indexLink">Index</a></li>
+<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
+</ul> <h2 id="pkg-overview">Overview </h2> <p>Package strings implements simple functions to manipulate UTF-8 encoded strings. </p>
+<p>For information about UTF-8 strings in Go, see <a href="https://blog.golang.org/strings">https://blog.golang.org/strings</a>. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
+<li><a href="#Clone">func Clone(s string) string</a></li>
+<li><a href="#Compare">func Compare(a, b string) int</a></li>
+<li><a href="#Contains">func Contains(s, substr string) bool</a></li>
+<li><a href="#ContainsAny">func ContainsAny(s, chars string) bool</a></li>
+<li><a href="#ContainsFunc">func ContainsFunc(s string, f func(rune) bool) bool</a></li>
+<li><a href="#ContainsRune">func ContainsRune(s string, r rune) bool</a></li>
+<li><a href="#Count">func Count(s, substr string) int</a></li>
+<li><a href="#Cut">func Cut(s, sep string) (before, after string, found bool)</a></li>
+<li><a href="#CutPrefix">func CutPrefix(s, prefix string) (after string, found bool)</a></li>
+<li><a href="#CutSuffix">func CutSuffix(s, suffix string) (before string, found bool)</a></li>
+<li><a href="#EqualFold">func EqualFold(s, t string) bool</a></li>
+<li><a href="#Fields">func Fields(s string) []string</a></li>
+<li><a href="#FieldsFunc">func FieldsFunc(s string, f func(rune) bool) []string</a></li>
+<li><a href="#HasPrefix">func HasPrefix(s, prefix string) bool</a></li>
+<li><a href="#HasSuffix">func HasSuffix(s, suffix string) bool</a></li>
+<li><a href="#Index">func Index(s, substr string) int</a></li>
+<li><a href="#IndexAny">func IndexAny(s, chars string) int</a></li>
+<li><a href="#IndexByte">func IndexByte(s string, c byte) int</a></li>
+<li><a href="#IndexFunc">func IndexFunc(s string, f func(rune) bool) int</a></li>
+<li><a href="#IndexRune">func IndexRune(s string, r rune) int</a></li>
+<li><a href="#Join">func Join(elems []string, sep string) string</a></li>
+<li><a href="#LastIndex">func LastIndex(s, substr string) int</a></li>
+<li><a href="#LastIndexAny">func LastIndexAny(s, chars string) int</a></li>
+<li><a href="#LastIndexByte">func LastIndexByte(s string, c byte) int</a></li>
+<li><a href="#LastIndexFunc">func LastIndexFunc(s string, f func(rune) bool) int</a></li>
+<li><a href="#Map">func Map(mapping func(rune) rune, s string) string</a></li>
+<li><a href="#Repeat">func Repeat(s string, count int) string</a></li>
+<li><a href="#Replace">func Replace(s, old, new string, n int) string</a></li>
+<li><a href="#ReplaceAll">func ReplaceAll(s, old, new string) string</a></li>
+<li><a href="#Split">func Split(s, sep string) []string</a></li>
+<li><a href="#SplitAfter">func SplitAfter(s, sep string) []string</a></li>
+<li><a href="#SplitAfterN">func SplitAfterN(s, sep string, n int) []string</a></li>
+<li><a href="#SplitN">func SplitN(s, sep string, n int) []string</a></li>
+<li><a href="#Title">func Title(s string) string</a></li>
+<li><a href="#ToLower">func ToLower(s string) string</a></li>
+<li><a href="#ToLowerSpecial">func ToLowerSpecial(c unicode.SpecialCase, s string) string</a></li>
+<li><a href="#ToTitle">func ToTitle(s string) string</a></li>
+<li><a href="#ToTitleSpecial">func ToTitleSpecial(c unicode.SpecialCase, s string) string</a></li>
+<li><a href="#ToUpper">func ToUpper(s string) string</a></li>
+<li><a href="#ToUpperSpecial">func ToUpperSpecial(c unicode.SpecialCase, s string) string</a></li>
+<li><a href="#ToValidUTF8">func ToValidUTF8(s, replacement string) string</a></li>
+<li><a href="#Trim">func Trim(s, cutset string) string</a></li>
+<li><a href="#TrimFunc">func TrimFunc(s string, f func(rune) bool) string</a></li>
+<li><a href="#TrimLeft">func TrimLeft(s, cutset string) string</a></li>
+<li><a href="#TrimLeftFunc">func TrimLeftFunc(s string, f func(rune) bool) string</a></li>
+<li><a href="#TrimPrefix">func TrimPrefix(s, prefix string) string</a></li>
+<li><a href="#TrimRight">func TrimRight(s, cutset string) string</a></li>
+<li><a href="#TrimRightFunc">func TrimRightFunc(s string, f func(rune) bool) string</a></li>
+<li><a href="#TrimSpace">func TrimSpace(s string) string</a></li>
+<li><a href="#TrimSuffix">func TrimSuffix(s, suffix string) string</a></li>
+<li><a href="#Builder">type Builder</a></li>
+<li> <a href="#Builder.Cap">func (b *Builder) Cap() int</a>
+</li>
+<li> <a href="#Builder.Grow">func (b *Builder) Grow(n int)</a>
+</li>
+<li> <a href="#Builder.Len">func (b *Builder) Len() int</a>
+</li>
+<li> <a href="#Builder.Reset">func (b *Builder) Reset()</a>
+</li>
+<li> <a href="#Builder.String">func (b *Builder) String() string</a>
+</li>
+<li> <a href="#Builder.Write">func (b *Builder) Write(p []byte) (int, error)</a>
+</li>
+<li> <a href="#Builder.WriteByte">func (b *Builder) WriteByte(c byte) error</a>
+</li>
+<li> <a href="#Builder.WriteRune">func (b *Builder) WriteRune(r rune) (int, error)</a>
+</li>
+<li> <a href="#Builder.WriteString">func (b *Builder) WriteString(s string) (int, error)</a>
+</li>
+<li><a href="#Reader">type Reader</a></li>
+<li> <a href="#NewReader">func NewReader(s string) *Reader</a>
+</li>
+<li> <a href="#Reader.Len">func (r *Reader) Len() int</a>
+</li>
+<li> <a href="#Reader.Read">func (r *Reader) Read(b []byte) (n int, err error)</a>
+</li>
+<li> <a href="#Reader.ReadAt">func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)</a>
+</li>
+<li> <a href="#Reader.ReadByte">func (r *Reader) ReadByte() (byte, error)</a>
+</li>
+<li> <a href="#Reader.ReadRune">func (r *Reader) ReadRune() (ch rune, size int, err error)</a>
+</li>
+<li> <a href="#Reader.Reset">func (r *Reader) Reset(s string)</a>
+</li>
+<li> <a href="#Reader.Seek">func (r *Reader) Seek(offset int64, whence int) (int64, error)</a>
+</li>
+<li> <a href="#Reader.Size">func (r *Reader) Size() int64</a>
+</li>
+<li> <a href="#Reader.UnreadByte">func (r *Reader) UnreadByte() error</a>
+</li>
+<li> <a href="#Reader.UnreadRune">func (r *Reader) UnreadRune() error</a>
+</li>
+<li> <a href="#Reader.WriteTo">func (r *Reader) WriteTo(w io.Writer) (n int64, err error)</a>
+</li>
+<li><a href="#Replacer">type Replacer</a></li>
+<li> <a href="#NewReplacer">func NewReplacer(oldnew ...string) *Replacer</a>
+</li>
+<li> <a href="#Replacer.Replace">func (r *Replacer) Replace(s string) string</a>
+</li>
+<li> <a href="#Replacer.WriteString">func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)</a>
+</li>
+</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_Builder">Builder</a></dd> <dd><a class="exampleLink" href="#example_Clone">Clone</a></dd> <dd><a class="exampleLink" href="#example_Compare">Compare</a></dd> <dd><a class="exampleLink" href="#example_Contains">Contains</a></dd> <dd><a class="exampleLink" href="#example_ContainsAny">ContainsAny</a></dd> <dd><a class="exampleLink" href="#example_ContainsFunc">ContainsFunc</a></dd> <dd><a class="exampleLink" href="#example_ContainsRune">ContainsRune</a></dd> <dd><a class="exampleLink" href="#example_Count">Count</a></dd> <dd><a class="exampleLink" href="#example_Cut">Cut</a></dd> <dd><a class="exampleLink" href="#example_CutPrefix">CutPrefix</a></dd> <dd><a class="exampleLink" href="#example_CutSuffix">CutSuffix</a></dd> <dd><a class="exampleLink" href="#example_EqualFold">EqualFold</a></dd> <dd><a class="exampleLink" href="#example_Fields">Fields</a></dd> <dd><a class="exampleLink" href="#example_FieldsFunc">FieldsFunc</a></dd> <dd><a class="exampleLink" href="#example_HasPrefix">HasPrefix</a></dd> <dd><a class="exampleLink" href="#example_HasSuffix">HasSuffix</a></dd> <dd><a class="exampleLink" href="#example_Index">Index</a></dd> <dd><a class="exampleLink" href="#example_IndexAny">IndexAny</a></dd> <dd><a class="exampleLink" href="#example_IndexByte">IndexByte</a></dd> <dd><a class="exampleLink" href="#example_IndexFunc">IndexFunc</a></dd> <dd><a class="exampleLink" href="#example_IndexRune">IndexRune</a></dd> <dd><a class="exampleLink" href="#example_Join">Join</a></dd> <dd><a class="exampleLink" href="#example_LastIndex">LastIndex</a></dd> <dd><a class="exampleLink" href="#example_LastIndexAny">LastIndexAny</a></dd> <dd><a class="exampleLink" href="#example_LastIndexByte">LastIndexByte</a></dd> <dd><a class="exampleLink" href="#example_LastIndexFunc">LastIndexFunc</a></dd> <dd><a class="exampleLink" href="#example_Map">Map</a></dd> <dd><a class="exampleLink" href="#example_NewReplacer">NewReplacer</a></dd> <dd><a class="exampleLink" href="#example_Repeat">Repeat</a></dd> <dd><a class="exampleLink" href="#example_Replace">Replace</a></dd> <dd><a class="exampleLink" href="#example_ReplaceAll">ReplaceAll</a></dd> <dd><a class="exampleLink" href="#example_Split">Split</a></dd> <dd><a class="exampleLink" href="#example_SplitAfter">SplitAfter</a></dd> <dd><a class="exampleLink" href="#example_SplitAfterN">SplitAfterN</a></dd> <dd><a class="exampleLink" href="#example_SplitN">SplitN</a></dd> <dd><a class="exampleLink" href="#example_Title">Title</a></dd> <dd><a class="exampleLink" href="#example_ToLower">ToLower</a></dd> <dd><a class="exampleLink" href="#example_ToLowerSpecial">ToLowerSpecial</a></dd> <dd><a class="exampleLink" href="#example_ToTitle">ToTitle</a></dd> <dd><a class="exampleLink" href="#example_ToTitleSpecial">ToTitleSpecial</a></dd> <dd><a class="exampleLink" href="#example_ToUpper">ToUpper</a></dd> <dd><a class="exampleLink" href="#example_ToUpperSpecial">ToUpperSpecial</a></dd> <dd><a class="exampleLink" href="#example_ToValidUTF8">ToValidUTF8</a></dd> <dd><a class="exampleLink" href="#example_Trim">Trim</a></dd> <dd><a class="exampleLink" href="#example_TrimFunc">TrimFunc</a></dd> <dd><a class="exampleLink" href="#example_TrimLeft">TrimLeft</a></dd> <dd><a class="exampleLink" href="#example_TrimLeftFunc">TrimLeftFunc</a></dd> <dd><a class="exampleLink" href="#example_TrimPrefix">TrimPrefix</a></dd> <dd><a class="exampleLink" href="#example_TrimRight">TrimRight</a></dd> <dd><a class="exampleLink" href="#example_TrimRightFunc">TrimRightFunc</a></dd> <dd><a class="exampleLink" href="#example_TrimSpace">TrimSpace</a></dd> <dd><a class="exampleLink" href="#example_TrimSuffix">TrimSuffix</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>builder.go</span> <span>clone.go</span> <span>compare.go</span> <span>reader.go</span> <span>replace.go</span> <span>search.go</span> <span>strings.go</span> </p> <h2 id="Clone">func <span>Clone</span> <span title="Added in Go 1.18">1.18</span> </h2> <pre data-language="go">func Clone(s string) string</pre> <p>Clone returns a fresh copy of s. It guarantees to make a copy of s into a new allocation, which can be important when retaining only a small substring of a much larger string. Using Clone can help such programs use less memory. Of course, since using Clone makes a copy, overuse of Clone can make programs use more memory. Clone should typically be used only rarely, and only when profiling indicates that it is needed. For strings of length zero the string "" will be returned and no allocation is made. </p> <h4 id="example_Clone"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">s := "abc"
+clone := strings.Clone(s)
+fmt.Println(s == clone)
+fmt.Println(unsafe.StringData(s) == unsafe.StringData(clone))
+</pre> <p>Output:</p> <pre class="output" data-language="go">true
+false
+</pre> <h2 id="Compare">func <span>Compare</span> <span title="Added in Go 1.5">1.5</span> </h2> <pre data-language="go">func Compare(a, b string) int</pre> <p>Compare returns an integer comparing two strings lexicographically. The result will be 0 if a == b, -1 if a &lt; b, and +1 if a &gt; b. </p>
+<p>Compare is included only for symmetry with package bytes. It is usually clearer and always faster to use the built-in string comparison operators ==, &lt;, &gt;, and so on. </p> <h4 id="example_Compare"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.Compare("a", "b"))
+fmt.Println(strings.Compare("a", "a"))
+fmt.Println(strings.Compare("b", "a"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">-1
+0
+1
+</pre> <h2 id="Contains">func <span>Contains</span> </h2> <pre data-language="go">func Contains(s, substr string) bool</pre> <p>Contains reports whether substr is within s. </p> <h4 id="example_Contains"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.Contains("seafood", "foo"))
+fmt.Println(strings.Contains("seafood", "bar"))
+fmt.Println(strings.Contains("seafood", ""))
+fmt.Println(strings.Contains("", ""))
+</pre> <p>Output:</p> <pre class="output" data-language="go">true
+false
+true
+true
+</pre> <h2 id="ContainsAny">func <span>ContainsAny</span> </h2> <pre data-language="go">func ContainsAny(s, chars string) bool</pre> <p>ContainsAny reports whether any Unicode code points in chars are within s. </p> <h4 id="example_ContainsAny"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.ContainsAny("team", "i"))
+fmt.Println(strings.ContainsAny("fail", "ui"))
+fmt.Println(strings.ContainsAny("ure", "ui"))
+fmt.Println(strings.ContainsAny("failure", "ui"))
+fmt.Println(strings.ContainsAny("foo", ""))
+fmt.Println(strings.ContainsAny("", ""))
+</pre> <p>Output:</p> <pre class="output" data-language="go">false
+true
+true
+true
+false
+false
+</pre> <h2 id="ContainsFunc">func <span>ContainsFunc</span> <span title="Added in Go 1.21">1.21</span> </h2> <pre data-language="go">func ContainsFunc(s string, f func(rune) bool) bool</pre> <p>ContainsFunc reports whether any Unicode code points r within s satisfy f(r). </p> <h4 id="example_ContainsFunc"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">f := func(r rune) bool {
+ return r == 'a' || r == 'e' || r == 'i' || r == 'o' || r == 'u'
+}
+fmt.Println(strings.ContainsFunc("hello", f))
+fmt.Println(strings.ContainsFunc("rhythms", f))
+</pre> <p>Output:</p> <pre class="output" data-language="go">true
+false
+</pre> <h2 id="ContainsRune">func <span>ContainsRune</span> </h2> <pre data-language="go">func ContainsRune(s string, r rune) bool</pre> <p>ContainsRune reports whether the Unicode code point r is within s. </p> <h4 id="example_ContainsRune"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">// 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))
+</pre> <p>Output:</p> <pre class="output" data-language="go">true
+false
+</pre> <h2 id="Count">func <span>Count</span> </h2> <pre data-language="go">func Count(s, substr string) int</pre> <p>Count counts the number of non-overlapping instances of substr in s. If substr is an empty string, Count returns 1 + the number of Unicode code points in s. </p> <h4 id="example_Count"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.Count("cheese", "e"))
+fmt.Println(strings.Count("five", "")) // before &amp; after each rune
+</pre> <p>Output:</p> <pre class="output" data-language="go">3
+5
+</pre> <h2 id="Cut">func <span>Cut</span> <span title="Added in Go 1.18">1.18</span> </h2> <pre data-language="go">func Cut(s, sep string) (before, after string, found bool)</pre> <p>Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false. </p> <h4 id="example_Cut"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">show := func(s, sep string) {
+ before, after, found := strings.Cut(s, sep)
+ fmt.Printf("Cut(%q, %q) = %q, %q, %v\n", s, sep, before, after, found)
+}
+show("Gopher", "Go")
+show("Gopher", "ph")
+show("Gopher", "er")
+show("Gopher", "Badger")
+</pre> <p>Output:</p> <pre class="output" data-language="go">Cut("Gopher", "Go") = "", "pher", true
+Cut("Gopher", "ph") = "Go", "er", true
+Cut("Gopher", "er") = "Goph", "", true
+Cut("Gopher", "Badger") = "Gopher", "", false
+</pre> <h2 id="CutPrefix">func <span>CutPrefix</span> <span title="Added in Go 1.20">1.20</span> </h2> <pre data-language="go">func CutPrefix(s, prefix string) (after string, found bool)</pre> <p>CutPrefix returns s without the provided leading prefix string and reports whether it found the prefix. If s doesn't start with prefix, CutPrefix returns s, false. If prefix is the empty string, CutPrefix returns s, true. </p> <h4 id="example_CutPrefix"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">show := func(s, sep string) {
+ after, found := strings.CutPrefix(s, sep)
+ fmt.Printf("CutPrefix(%q, %q) = %q, %v\n", s, sep, after, found)
+}
+show("Gopher", "Go")
+show("Gopher", "ph")
+</pre> <p>Output:</p> <pre class="output" data-language="go">CutPrefix("Gopher", "Go") = "pher", true
+CutPrefix("Gopher", "ph") = "Gopher", false
+</pre> <h2 id="CutSuffix">func <span>CutSuffix</span> <span title="Added in Go 1.20">1.20</span> </h2> <pre data-language="go">func CutSuffix(s, suffix string) (before string, found bool)</pre> <p>CutSuffix returns s without the provided ending suffix string and reports whether it found the suffix. If s doesn't end with suffix, CutSuffix returns s, false. If suffix is the empty string, CutSuffix returns s, true. </p> <h4 id="example_CutSuffix"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">show := func(s, sep string) {
+ before, found := strings.CutSuffix(s, sep)
+ fmt.Printf("CutSuffix(%q, %q) = %q, %v\n", s, sep, before, found)
+}
+show("Gopher", "Go")
+show("Gopher", "er")
+</pre> <p>Output:</p> <pre class="output" data-language="go">CutSuffix("Gopher", "Go") = "Gopher", false
+CutSuffix("Gopher", "er") = "Goph", true
+</pre> <h2 id="EqualFold">func <span>EqualFold</span> </h2> <pre data-language="go">func EqualFold(s, t string) bool</pre> <p>EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity. </p> <h4 id="example_EqualFold"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.EqualFold("Go", "go"))
+fmt.Println(strings.EqualFold("AB", "ab")) // true because comparison uses simple case-folding
+fmt.Println(strings.EqualFold("ß", "ss")) // false because comparison does not use full case-folding
+</pre> <p>Output:</p> <pre class="output" data-language="go">true
+true
+false
+</pre> <h2 id="Fields">func <span>Fields</span> </h2> <pre data-language="go">func Fields(s string) []string</pre> <p>Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space. </p> <h4 id="example_Fields"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Printf("Fields are: %q", strings.Fields(" foo bar baz "))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Fields are: ["foo" "bar" "baz"]
+</pre> <h2 id="FieldsFunc">func <span>FieldsFunc</span> </h2> <pre data-language="go">func FieldsFunc(s string, f func(rune) bool) []string</pre> <p>FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned. </p>
+<p>FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c. </p> <h4 id="example_FieldsFunc"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">f := func(c rune) bool {
+ return !unicode.IsLetter(c) &amp;&amp; !unicode.IsNumber(c)
+}
+fmt.Printf("Fields are: %q", strings.FieldsFunc(" foo1;bar2,baz3...", f))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Fields are: ["foo1" "bar2" "baz3"]
+</pre> <h2 id="HasPrefix">func <span>HasPrefix</span> </h2> <pre data-language="go">func HasPrefix(s, prefix string) bool</pre> <p>HasPrefix reports whether the string s begins with prefix. </p> <h4 id="example_HasPrefix"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.HasPrefix("Gopher", "Go"))
+fmt.Println(strings.HasPrefix("Gopher", "C"))
+fmt.Println(strings.HasPrefix("Gopher", ""))
+</pre> <p>Output:</p> <pre class="output" data-language="go">true
+false
+true
+</pre> <h2 id="HasSuffix">func <span>HasSuffix</span> </h2> <pre data-language="go">func HasSuffix(s, suffix string) bool</pre> <p>HasSuffix reports whether the string s ends with suffix. </p> <h4 id="example_HasSuffix"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.HasSuffix("Amigo", "go"))
+fmt.Println(strings.HasSuffix("Amigo", "O"))
+fmt.Println(strings.HasSuffix("Amigo", "Ami"))
+fmt.Println(strings.HasSuffix("Amigo", ""))
+</pre> <p>Output:</p> <pre class="output" data-language="go">true
+false
+false
+true
+</pre> <h2 id="Index">func <span>Index</span> </h2> <pre data-language="go">func Index(s, substr string) int</pre> <p>Index returns the index of the first instance of substr in s, or -1 if substr is not present in s. </p> <h4 id="example_Index"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.Index("chicken", "ken"))
+fmt.Println(strings.Index("chicken", "dmr"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">4
+-1
+</pre> <h2 id="IndexAny">func <span>IndexAny</span> </h2> <pre data-language="go">func IndexAny(s, chars string) int</pre> <p>IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s. </p> <h4 id="example_IndexAny"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.IndexAny("chicken", "aeiouy"))
+fmt.Println(strings.IndexAny("crwth", "aeiouy"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">2
+-1
+</pre> <h2 id="IndexByte">func <span>IndexByte</span> <span title="Added in Go 1.2">1.2</span> </h2> <pre data-language="go">func IndexByte(s string, c byte) int</pre> <p>IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s. </p> <h4 id="example_IndexByte"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.IndexByte("golang", 'g'))
+fmt.Println(strings.IndexByte("gophers", 'h'))
+fmt.Println(strings.IndexByte("golang", 'x'))
+</pre> <p>Output:</p> <pre class="output" data-language="go">0
+3
+-1
+</pre> <h2 id="IndexFunc">func <span>IndexFunc</span> </h2> <pre data-language="go">func IndexFunc(s string, f func(rune) bool) int</pre> <p>IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do. </p> <h4 id="example_IndexFunc"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">f := func(c rune) bool {
+ return unicode.Is(unicode.Han, c)
+}
+fmt.Println(strings.IndexFunc("Hello, 世界", f))
+fmt.Println(strings.IndexFunc("Hello, world", f))
+</pre> <p>Output:</p> <pre class="output" data-language="go">7
+-1
+</pre> <h2 id="IndexRune">func <span>IndexRune</span> </h2> <pre data-language="go">func IndexRune(s string, r rune) int</pre> <p>IndexRune returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in s. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence. </p> <h4 id="example_IndexRune"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.IndexRune("chicken", 'k'))
+fmt.Println(strings.IndexRune("chicken", 'd'))
+</pre> <p>Output:</p> <pre class="output" data-language="go">4
+-1
+</pre> <h2 id="Join">func <span>Join</span> </h2> <pre data-language="go">func Join(elems []string, sep string) string</pre> <p>Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string. </p> <h4 id="example_Join"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">s := []string{"foo", "bar", "baz"}
+fmt.Println(strings.Join(s, ", "))
+</pre> <p>Output:</p> <pre class="output" data-language="go">foo, bar, baz
+</pre> <h2 id="LastIndex">func <span>LastIndex</span> </h2> <pre data-language="go">func LastIndex(s, substr string) int</pre> <p>LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s. </p> <h4 id="example_LastIndex"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.Index("go gopher", "go"))
+fmt.Println(strings.LastIndex("go gopher", "go"))
+fmt.Println(strings.LastIndex("go gopher", "rodent"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">0
+3
+-1
+</pre> <h2 id="LastIndexAny">func <span>LastIndexAny</span> </h2> <pre data-language="go">func LastIndexAny(s, chars string) int</pre> <p>LastIndexAny returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s. </p> <h4 id="example_LastIndexAny"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.LastIndexAny("go gopher", "go"))
+fmt.Println(strings.LastIndexAny("go gopher", "rodent"))
+fmt.Println(strings.LastIndexAny("go gopher", "fail"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">4
+8
+-1
+</pre> <h2 id="LastIndexByte">func <span>LastIndexByte</span> <span title="Added in Go 1.5">1.5</span> </h2> <pre data-language="go">func LastIndexByte(s string, c byte) int</pre> <p>LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s. </p> <h4 id="example_LastIndexByte"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.LastIndexByte("Hello, world", 'l'))
+fmt.Println(strings.LastIndexByte("Hello, world", 'o'))
+fmt.Println(strings.LastIndexByte("Hello, world", 'x'))
+</pre> <p>Output:</p> <pre class="output" data-language="go">10
+8
+-1
+</pre> <h2 id="LastIndexFunc">func <span>LastIndexFunc</span> </h2> <pre data-language="go">func LastIndexFunc(s string, f func(rune) bool) int</pre> <p>LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do. </p> <h4 id="example_LastIndexFunc"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.LastIndexFunc("go 123", unicode.IsNumber))
+fmt.Println(strings.LastIndexFunc("123 go", unicode.IsNumber))
+fmt.Println(strings.LastIndexFunc("go", unicode.IsNumber))
+</pre> <p>Output:</p> <pre class="output" data-language="go">5
+2
+-1
+</pre> <h2 id="Map">func <span>Map</span> </h2> <pre data-language="go">func Map(mapping func(rune) rune, s string) string</pre> <p>Map returns a copy of the string s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement. </p> <h4 id="example_Map"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">rot13 := func(r rune) rune {
+ switch {
+ case r &gt;= 'A' &amp;&amp; r &lt;= 'Z':
+ return 'A' + (r-'A'+13)%26
+ case r &gt;= 'a' &amp;&amp; r &lt;= 'z':
+ return 'a' + (r-'a'+13)%26
+ }
+ return r
+}
+fmt.Println(strings.Map(rot13, "'Twas brillig and the slithy gopher..."))
+</pre> <p>Output:</p> <pre class="output" data-language="go">'Gjnf oevyyvt naq gur fyvgul tbcure...
+</pre> <h2 id="Repeat">func <span>Repeat</span> </h2> <pre data-language="go">func Repeat(s string, count int) string</pre> <p>Repeat returns a new string consisting of count copies of the string s. </p>
+<p>It panics if count is negative or if the result of (len(s) * count) overflows. </p> <h4 id="example_Repeat"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println("ba" + strings.Repeat("na", 2))
+</pre> <p>Output:</p> <pre class="output" data-language="go">banana
+</pre> <h2 id="Replace">func <span>Replace</span> </h2> <pre data-language="go">func Replace(s, old, new string, n int) string</pre> <p>Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n &lt; 0, there is no limit on the number of replacements. </p> <h4 id="example_Replace"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2))
+fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1))
+</pre> <p>Output:</p> <pre class="output" data-language="go">oinky oinky oink
+moo moo moo
+</pre> <h2 id="ReplaceAll">func <span>ReplaceAll</span> <span title="Added in Go 1.12">1.12</span> </h2> <pre data-language="go">func ReplaceAll(s, old, new string) string</pre> <p>ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. </p> <h4 id="example_ReplaceAll"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.ReplaceAll("oink oink oink", "oink", "moo"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">moo moo moo
+</pre> <h2 id="Split">func <span>Split</span> </h2> <pre data-language="go">func Split(s, sep string) []string</pre> <p>Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators. </p>
+<p>If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s. </p>
+<p>If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice. </p>
+<p>It is equivalent to <a href="#SplitN">SplitN</a> with a count of -1. </p>
+<p>To split around the first instance of a separator, see Cut. </p> <h4 id="example_Split"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">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"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">["a" "b" "c"]
+["" "man " "plan " "canal panama"]
+[" " "x" "y" "z" " "]
+[""]
+</pre> <h2 id="SplitAfter">func <span>SplitAfter</span> </h2> <pre data-language="go">func SplitAfter(s, sep string) []string</pre> <p>SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings. </p>
+<p>If s does not contain sep and sep is not empty, SplitAfter returns a slice of length 1 whose only element is s. </p>
+<p>If sep is empty, SplitAfter splits after each UTF-8 sequence. If both s and sep are empty, SplitAfter returns an empty slice. </p>
+<p>It is equivalent to <a href="#SplitAfterN">SplitAfterN</a> with a count of -1. </p> <h4 id="example_SplitAfter"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Printf("%q\n", strings.SplitAfter("a,b,c", ","))
+</pre> <p>Output:</p> <pre class="output" data-language="go">["a," "b," "c"]
+</pre> <h2 id="SplitAfterN">func <span>SplitAfterN</span> </h2> <pre data-language="go">func SplitAfterN(s, sep string, n int) []string</pre> <p>SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings. </p>
+<p>The count determines the number of substrings to return: </p>
+<pre data-language="go">n &gt; 0: at most n substrings; the last substring will be the unsplit remainder.
+n == 0: the result is nil (zero substrings)
+n &lt; 0: all substrings
+</pre> <p>Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for SplitAfter. </p> <h4 id="example_SplitAfterN"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", 2))
+</pre> <p>Output:</p> <pre class="output" data-language="go">["a," "b,c"]
+</pre> <h2 id="SplitN">func <span>SplitN</span> </h2> <pre data-language="go">func SplitN(s, sep string, n int) []string</pre> <p>SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators. </p>
+<p>The count determines the number of substrings to return: </p>
+<pre data-language="go">n &gt; 0: at most n substrings; the last substring will be the unsplit remainder.
+n == 0: the result is nil (zero substrings)
+n &lt; 0: all substrings
+</pre> <p>Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for <a href="#Split">Split</a>. </p>
+<p>To split around the first instance of a separator, see Cut. </p> <h4 id="example_SplitN"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">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)
+</pre> <p>Output:</p> <pre class="output" data-language="go">["a" "b,c"]
+[] (nil = true)
+</pre> <h2 id="Title">func <span>Title</span> </h2> <pre data-language="go">func Title(s string) string</pre> <p>Title returns a copy of the string s with all Unicode letters that begin words mapped to their Unicode title case. </p>
+<p>Deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead. </p> <h4 id="example_Title"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">// Compare this example to the ToTitle example.
+fmt.Println(strings.Title("her royal highness"))
+fmt.Println(strings.Title("loud noises"))
+fmt.Println(strings.Title("хлеб"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Her Royal Highness
+Loud Noises
+Хлеб
+</pre> <h2 id="ToLower">func <span>ToLower</span> </h2> <pre data-language="go">func ToLower(s string) string</pre> <p>ToLower returns s with all Unicode letters mapped to their lower case. </p> <h4 id="example_ToLower"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.ToLower("Gopher"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">gopher
+</pre> <h2 id="ToLowerSpecial">func <span>ToLowerSpecial</span> </h2> <pre data-language="go">func ToLowerSpecial(c unicode.SpecialCase, s string) string</pre> <p>ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their lower case using the case mapping specified by c. </p> <h4 id="example_ToLowerSpecial"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.ToLowerSpecial(unicode.TurkishCase, "Önnek İş"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">önnek iş
+</pre> <h2 id="ToTitle">func <span>ToTitle</span> </h2> <pre data-language="go">func ToTitle(s string) string</pre> <p>ToTitle returns a copy of the string s with all Unicode letters mapped to their Unicode title case. </p> <h4 id="example_ToTitle"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">// Compare this example to the Title example.
+fmt.Println(strings.ToTitle("her royal highness"))
+fmt.Println(strings.ToTitle("loud noises"))
+fmt.Println(strings.ToTitle("хлеб"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">HER ROYAL HIGHNESS
+LOUD NOISES
+ХЛЕБ
+</pre> <h2 id="ToTitleSpecial">func <span>ToTitleSpecial</span> </h2> <pre data-language="go">func ToTitleSpecial(c unicode.SpecialCase, s string) string</pre> <p>ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their Unicode title case, giving priority to the special casing rules. </p> <h4 id="example_ToTitleSpecial"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.ToTitleSpecial(unicode.TurkishCase, "dünyanın ilk borsa yapısı Aizonai kabul edilir"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">DÜNYANIN İLK BORSA YAPISI AİZONAİ KABUL EDİLİR
+</pre> <h2 id="ToUpper">func <span>ToUpper</span> </h2> <pre data-language="go">func ToUpper(s string) string</pre> <p>ToUpper returns s with all Unicode letters mapped to their upper case. </p> <h4 id="example_ToUpper"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.ToUpper("Gopher"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">GOPHER
+</pre> <h2 id="ToUpperSpecial">func <span>ToUpperSpecial</span> </h2> <pre data-language="go">func ToUpperSpecial(c unicode.SpecialCase, s string) string</pre> <p>ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their upper case using the case mapping specified by c. </p> <h4 id="example_ToUpperSpecial"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.ToUpperSpecial(unicode.TurkishCase, "örnek iş"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">ÖRNEK İŞ
+</pre> <h2 id="ToValidUTF8">func <span>ToValidUTF8</span> <span title="Added in Go 1.13">1.13</span> </h2> <pre data-language="go">func ToValidUTF8(s, replacement string) string</pre> <p>ToValidUTF8 returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty. </p> <h4 id="example_ToValidUTF8"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Printf("%s\n", strings.ToValidUTF8("abc", "\uFFFD"))
+fmt.Printf("%s\n", strings.ToValidUTF8("a\xffb\xC0\xAFc\xff", ""))
+fmt.Printf("%s\n", strings.ToValidUTF8("\xed\xa0\x80", "abc"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">abc
+abc
+abc
+</pre> <h2 id="Trim">func <span>Trim</span> </h2> <pre data-language="go">func Trim(s, cutset string) string</pre> <p>Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed. </p> <h4 id="example_Trim"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Print(strings.Trim("¡¡¡Hello, Gophers!!!", "!¡"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Hello, Gophers
+</pre> <h2 id="TrimFunc">func <span>TrimFunc</span> </h2> <pre data-language="go">func TrimFunc(s string, f func(rune) bool) string</pre> <p>TrimFunc returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed. </p> <h4 id="example_TrimFunc"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Print(strings.TrimFunc("¡¡¡Hello, Gophers!!!", func(r rune) bool {
+ return !unicode.IsLetter(r) &amp;&amp; !unicode.IsNumber(r)
+}))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Hello, Gophers
+</pre> <h2 id="TrimLeft">func <span>TrimLeft</span> </h2> <pre data-language="go">func TrimLeft(s, cutset string) string</pre> <p>TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed. </p>
+<p>To remove a prefix, use <a href="#TrimPrefix">TrimPrefix</a> instead. </p> <h4 id="example_TrimLeft"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Print(strings.TrimLeft("¡¡¡Hello, Gophers!!!", "!¡"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Hello, Gophers!!!
+</pre> <h2 id="TrimLeftFunc">func <span>TrimLeftFunc</span> </h2> <pre data-language="go">func TrimLeftFunc(s string, f func(rune) bool) string</pre> <p>TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed. </p> <h4 id="example_TrimLeftFunc"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Print(strings.TrimLeftFunc("¡¡¡Hello, Gophers!!!", func(r rune) bool {
+ return !unicode.IsLetter(r) &amp;&amp; !unicode.IsNumber(r)
+}))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Hello, Gophers!!!
+</pre> <h2 id="TrimPrefix">func <span>TrimPrefix</span> <span title="Added in Go 1.1">1.1</span> </h2> <pre data-language="go">func TrimPrefix(s, prefix string) string</pre> <p>TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged. </p> <h4 id="example_TrimPrefix"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">var s = "¡¡¡Hello, Gophers!!!"
+s = strings.TrimPrefix(s, "¡¡¡Hello, ")
+s = strings.TrimPrefix(s, "¡¡¡Howdy, ")
+fmt.Print(s)
+</pre> <p>Output:</p> <pre class="output" data-language="go">Gophers!!!
+</pre> <h2 id="TrimRight">func <span>TrimRight</span> </h2> <pre data-language="go">func TrimRight(s, cutset string) string</pre> <p>TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed. </p>
+<p>To remove a suffix, use <a href="#TrimSuffix">TrimSuffix</a> instead. </p> <h4 id="example_TrimRight"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Print(strings.TrimRight("¡¡¡Hello, Gophers!!!", "!¡"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">¡¡¡Hello, Gophers
+</pre> <h2 id="TrimRightFunc">func <span>TrimRightFunc</span> </h2> <pre data-language="go">func TrimRightFunc(s string, f func(rune) bool) string</pre> <p>TrimRightFunc returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed. </p> <h4 id="example_TrimRightFunc"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Print(strings.TrimRightFunc("¡¡¡Hello, Gophers!!!", func(r rune) bool {
+ return !unicode.IsLetter(r) &amp;&amp; !unicode.IsNumber(r)
+}))
+</pre> <p>Output:</p> <pre class="output" data-language="go">¡¡¡Hello, Gophers
+</pre> <h2 id="TrimSpace">func <span>TrimSpace</span> </h2> <pre data-language="go">func TrimSpace(s string) string</pre> <p>TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode. </p> <h4 id="example_TrimSpace"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(strings.TrimSpace(" \t\n Hello, Gophers \n\t\r\n"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">Hello, Gophers
+</pre> <h2 id="TrimSuffix">func <span>TrimSuffix</span> <span title="Added in Go 1.1">1.1</span> </h2> <pre data-language="go">func TrimSuffix(s, suffix string) string</pre> <p>TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged. </p> <h4 id="example_TrimSuffix"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">var s = "¡¡¡Hello, Gophers!!!"
+s = strings.TrimSuffix(s, ", Gophers!!!")
+s = strings.TrimSuffix(s, ", Marmots!!!")
+fmt.Print(s)
+</pre> <p>Output:</p> <pre class="output" data-language="go">¡¡¡Hello
+</pre> <h2 id="Builder">type <span>Builder</span> <span title="Added in Go 1.10">1.10</span> </h2> <p>A Builder is used to efficiently build a string using <a href="#Builder.Write">Builder.Write</a> methods. It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder. </p>
+<pre data-language="go">type Builder struct {
+ // contains filtered or unexported fields
+}
+</pre> <h4 id="example_Builder"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">var b strings.Builder
+for i := 3; i &gt;= 1; i-- {
+ fmt.Fprintf(&amp;b, "%d...", i)
+}
+b.WriteString("ignition")
+fmt.Println(b.String())
+
+</pre> <p>Output:</p> <pre class="output" data-language="go">3...2...1...ignition
+</pre> <h3 id="Builder.Cap">func (*Builder) <span>Cap</span> <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (b *Builder) Cap() int</pre> <p>Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written. </p>
+<h3 id="Builder.Grow">func (*Builder) <span>Grow</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) Grow(n int)</pre> <p>Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics. </p>
+<h3 id="Builder.Len">func (*Builder) <span>Len</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) Len() int</pre> <p>Len returns the number of accumulated bytes; b.Len() == len(b.String()). </p>
+<h3 id="Builder.Reset">func (*Builder) <span>Reset</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) Reset()</pre> <p>Reset resets the <a href="#Builder">Builder</a> to be empty. </p>
+<h3 id="Builder.String">func (*Builder) <span>String</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) String() string</pre> <p>String returns the accumulated string. </p>
+<h3 id="Builder.Write">func (*Builder) <span>Write</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) Write(p []byte) (int, error)</pre> <p>Write appends the contents of p to b's buffer. Write always returns len(p), nil. </p>
+<h3 id="Builder.WriteByte">func (*Builder) <span>WriteByte</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) WriteByte(c byte) error</pre> <p>WriteByte appends the byte c to b's buffer. The returned error is always nil. </p>
+<h3 id="Builder.WriteRune">func (*Builder) <span>WriteRune</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) WriteRune(r rune) (int, error)</pre> <p>WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error. </p>
+<h3 id="Builder.WriteString">func (*Builder) <span>WriteString</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (b *Builder) WriteString(s string) (int, error)</pre> <p>WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error. </p>
+<h2 id="Reader">type <span>Reader</span> </h2> <p>A Reader implements the <span>io.Reader</span>, <span>io.ReaderAt</span>, <span>io.ByteReader</span>, <span>io.ByteScanner</span>, <span>io.RuneReader</span>, <span>io.RuneScanner</span>, <span>io.Seeker</span>, and <span>io.WriterTo</span> interfaces by reading from a string. The zero value for Reader operates like a Reader of an empty string. </p>
+<pre data-language="go">type Reader struct {
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="NewReader">func <span>NewReader</span> </h3> <pre data-language="go">func NewReader(s string) *Reader</pre> <p>NewReader returns a new <a href="#Reader">Reader</a> reading from s. It is similar to <span>bytes.NewBufferString</span> but more efficient and non-writable. </p>
+<h3 id="Reader.Len">func (*Reader) <span>Len</span> </h3> <pre data-language="go">func (r *Reader) Len() int</pre> <p>Len returns the number of bytes of the unread portion of the string. </p>
+<h3 id="Reader.Read">func (*Reader) <span>Read</span> </h3> <pre data-language="go">func (r *Reader) Read(b []byte) (n int, err error)</pre> <p>Read implements the <span>io.Reader</span> interface. </p>
+<h3 id="Reader.ReadAt">func (*Reader) <span>ReadAt</span> </h3> <pre data-language="go">func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)</pre> <p>ReadAt implements the <span>io.ReaderAt</span> interface. </p>
+<h3 id="Reader.ReadByte">func (*Reader) <span>ReadByte</span> </h3> <pre data-language="go">func (r *Reader) ReadByte() (byte, error)</pre> <p>ReadByte implements the <span>io.ByteReader</span> interface. </p>
+<h3 id="Reader.ReadRune">func (*Reader) <span>ReadRune</span> </h3> <pre data-language="go">func (r *Reader) ReadRune() (ch rune, size int, err error)</pre> <p>ReadRune implements the <span>io.RuneReader</span> interface. </p>
+<h3 id="Reader.Reset">func (*Reader) <span>Reset</span> <span title="Added in Go 1.7">1.7</span> </h3> <pre data-language="go">func (r *Reader) Reset(s string)</pre> <p>Reset resets the <a href="#Reader">Reader</a> to be reading from s. </p>
+<h3 id="Reader.Seek">func (*Reader) <span>Seek</span> </h3> <pre data-language="go">func (r *Reader) Seek(offset int64, whence int) (int64, error)</pre> <p>Seek implements the <span>io.Seeker</span> interface. </p>
+<h3 id="Reader.Size">func (*Reader) <span>Size</span> <span title="Added in Go 1.5">1.5</span> </h3> <pre data-language="go">func (r *Reader) Size() int64</pre> <p>Size returns the original length of the underlying string. Size is the number of bytes available for reading via <a href="#Reader.ReadAt">Reader.ReadAt</a>. The returned value is always the same and is not affected by calls to any other method. </p>
+<h3 id="Reader.UnreadByte">func (*Reader) <span>UnreadByte</span> </h3> <pre data-language="go">func (r *Reader) UnreadByte() error</pre> <p>UnreadByte implements the <span>io.ByteScanner</span> interface. </p>
+<h3 id="Reader.UnreadRune">func (*Reader) <span>UnreadRune</span> </h3> <pre data-language="go">func (r *Reader) UnreadRune() error</pre> <p>UnreadRune implements the <span>io.RuneScanner</span> interface. </p>
+<h3 id="Reader.WriteTo">func (*Reader) <span>WriteTo</span> <span title="Added in Go 1.1">1.1</span> </h3> <pre data-language="go">func (r *Reader) WriteTo(w io.Writer) (n int64, err error)</pre> <p>WriteTo implements the <span>io.WriterTo</span> interface. </p>
+<h2 id="Replacer">type <span>Replacer</span> </h2> <p>Replacer replaces a list of strings with replacements. It is safe for concurrent use by multiple goroutines. </p>
+<pre data-language="go">type Replacer struct {
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="NewReplacer">func <span>NewReplacer</span> </h3> <pre data-language="go">func NewReplacer(oldnew ...string) *Replacer</pre> <p>NewReplacer returns a new <a href="#Replacer">Replacer</a> from a list of old, new string pairs. Replacements are performed in the order they appear in the target string, without overlapping matches. The old string comparisons are done in argument order. </p>
+<p>NewReplacer panics if given an odd number of arguments. </p> <h4 id="example_NewReplacer"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">r := strings.NewReplacer("&lt;", "&amp;lt;", "&gt;", "&amp;gt;")
+fmt.Println(r.Replace("This is &lt;b&gt;HTML&lt;/b&gt;!"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">This is &amp;lt;b&amp;gt;HTML&amp;lt;/b&amp;gt;!
+</pre> <h3 id="Replacer.Replace">func (*Replacer) <span>Replace</span> </h3> <pre data-language="go">func (r *Replacer) Replace(s string) string</pre> <p>Replace returns a copy of s with all replacements performed. </p>
+<h3 id="Replacer.WriteString">func (*Replacer) <span>WriteString</span> </h3> <pre data-language="go">func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)</pre> <p>WriteString writes s to w with all replacements performed. </p><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
+ <a href="http://golang.org/pkg/strings/" class="_attribution-link">http://golang.org/pkg/strings/</a>
+ </p>
+</div>