golang: Get last character of a string
25 Nov 2014 in TIL
A very quick one here. I needed to get the last character of a string in golang, but thinking like a PHP developer I was looking for an equivalent to substr($var, -1);
.
As it turns out, you actually do it using slices
go
newVal := val[len(val)-1:]
This says "start at string length, minus 1 and give me everything to the end"