Return last item of strings.Split() slice in Golang : <p>I am <a href="https://golang.org/pkg/strings/#Split" rel="noreferrer">splitting</a> file names in Go to get at the file extension (e.g. <code>import ("strings") ; strings.Split("example.txt", ".")</code>). 
For this reason, I would like to return the last item in the slice returned by the split, i.e. </p>

<blockquote>
  <p>for strings.Split("ex.txt", "."), I want txt</p>
</blockquote>

<p><a href="https://stackoverflow.com/questions/22535775/the-last-element-of-a-slice#22535888">This</a> question suggests that doing </p>

<pre><code>strings.Split("ex.txt", ".")[len(strings.Split("ex.txt", ".")) - 1]
</code></pre>

<p>is the only way to get at it. That is, there is no <code>-1</code> as in Python. This seems very wasteful to me, as I feel we are doing the same splitting operation twice. </p>

<ul>
<li>Is there no better command for getting the last item of a slice in Go?</li>
<li>If no, would the best approach be to write the result of <code>Split</code> into a variable, or just do the above?</li>
</ul>

<p>Thank you!</p>
