为什么这段代码会导致切片超出范围?

I have no idea why this code always slice bound out of range:

parts := make([]string, 0, len(encodedCode)/4)

for i := 0; i < len(encodedCode); i += 4 {
    parts = append(parts, encodedCode[i:4])
}

encodedCode is string with length always multiply with 4. That mean encodedCode[i:4] never out of bound.

Slices are [idx_start:idx_end+1], not [idx_start:length]

Try this.

parts := make([]string, 0, len(encodedCode)/4)
for i := 0; i < len(encodedCode); i += 4 {
    parts = append(parts, encodedCode[i:i+4])
}

Good examples @ http://blog.golang.org/go-slices-usage-and-internals