parent
e533ad365b
commit
cca7879dce
@ -14,10 +14,12 @@ var p = fmt.Println
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Here's a sample of the functions available in
|
// Here's a sample of the functions available in
|
||||||
// `strings`. Note that these are all functions from the
|
// `strings`. Since these are functions from the
|
||||||
// package, not methods on the string object itself.
|
// package, not methods on the string object itself,
|
||||||
// This means that we need pass the string in question
|
// we need pass the string in question as the first
|
||||||
// as the first argument to the function.
|
// argument to the function. You can find more
|
||||||
|
// functions in the [`strings`](http://golang.org/pkg/strings/)
|
||||||
|
// package docs.
|
||||||
p("Contains: ", s.Contains("test", "es"))
|
p("Contains: ", s.Contains("test", "es"))
|
||||||
p("Count: ", s.Count("test", "t"))
|
p("Count: ", s.Count("test", "t"))
|
||||||
p("HasPrefix: ", s.HasPrefix("test", "te"))
|
p("HasPrefix: ", s.HasPrefix("test", "te"))
|
||||||
@ -32,12 +34,16 @@ func main() {
|
|||||||
p("ToUpper: ", s.ToUpper("test"))
|
p("ToUpper: ", s.ToUpper("test"))
|
||||||
p()
|
p()
|
||||||
|
|
||||||
// You can find more functions in the [`strings`](http://golang.org/pkg/strings/)
|
// Not part of `strings`, but worth mentioning here, are
|
||||||
// package docs.
|
// the mechanisms for getting the length of a string in
|
||||||
|
// bytes and getting a byte by index.
|
||||||
// Not part of `strings` but worth mentioning here are
|
|
||||||
// the mechanisms for getting the length of a string
|
|
||||||
// and getting a character by index.
|
|
||||||
p("Len: ", len("hello"))
|
p("Len: ", len("hello"))
|
||||||
p("Char:", "hello"[1])
|
p("Char:", "hello"[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note that `len` and indexing above work at the byte level.
|
||||||
|
// Go uses UTF-8 encoded strings, so this is often useful
|
||||||
|
// as-is. If you're working with potentially multi-byte
|
||||||
|
// characters you'll want to use encoding-aware operations.
|
||||||
|
// See [strings, bytes, runes and characters in Go](https://blog.golang.org/strings)
|
||||||
|
// for more information.
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
d7150ce50772abdaf827082093613134cb05e08f
|
17aa523bbd606fa0b624fae44b89812d46330755
|
||||||
Gkc5rDaeaN
|
Lf5_Zbg6or
|
||||||
|
@ -41,7 +41,7 @@ to give you a sense of the package.</p>
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<td class="code leading">
|
||||||
<a href="http://play.golang.org/p/Gkc5rDaeaN"><img title="Run code" src="play.png" class="run" /></a>
|
<a href="http://play.golang.org/p/Lf5_Zbg6or"><img title="Run code" src="play.png" class="run" /></a>
|
||||||
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
@ -90,10 +90,12 @@ it a lot below.</p>
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p>Here’s a sample of the functions available in
|
<p>Here’s a sample of the functions available in
|
||||||
<code>strings</code>. Note that these are all functions from the
|
<code>strings</code>. Since these are functions from the
|
||||||
package, not methods on the string object itself.
|
package, not methods on the string object itself,
|
||||||
This means that we need pass the string in question
|
we need pass the string in question as the first
|
||||||
as the first argument to the function.</p>
|
argument to the function. You can find more
|
||||||
|
functions in the <a href="http://golang.org/pkg/strings/"><code>strings</code></a>
|
||||||
|
package docs.</p>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<td class="code leading">
|
||||||
@ -118,29 +120,33 @@ as the first argument to the function.</p>
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p>You can find more functions in the <a href="http://golang.org/pkg/strings/"><code>strings</code></a>
|
<p>Not part of <code>strings</code>, but worth mentioning here, are
|
||||||
package docs.</p>
|
the mechanisms for getting the length of a string in
|
||||||
|
bytes and getting a byte by index.</p>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code empty leading">
|
<td class="code leading">
|
||||||
|
|
||||||
|
<div class="highlight"><pre> <span class="nx">p</span><span class="p">(</span><span class="s">"Len: "</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="s">"hello"</span><span class="p">))</span>
|
||||||
|
<span class="nx">p</span><span class="p">(</span><span class="s">"Char:"</span><span class="p">,</span> <span class="s">"hello"</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
|
||||||
|
<span class="p">}</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p>Not part of <code>strings</code> but worth mentioning here are
|
<p>Note that <code>len</code> and indexing above work at the byte level.
|
||||||
the mechanisms for getting the length of a string
|
Go uses UTF-8 encoded strings, so this is often useful
|
||||||
and getting a character by index.</p>
|
as-is. If you’re working with potentially multi-byte
|
||||||
|
characters you’ll want to use encoding-aware operations.
|
||||||
|
See <a href="https://blog.golang.org/strings">strings, bytes, runes and characters in Go</a>
|
||||||
|
for more information.</p>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code">
|
<td class="code empty">
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">p</span><span class="p">(</span><span class="s">"Len: "</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="s">"hello"</span><span class="p">))</span>
|
|
||||||
<span class="nx">p</span><span class="p">(</span><span class="s">"Char:"</span><span class="p">,</span> <span class="s">"hello"</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user