Skip to content

Instantly share code, notes, and snippets.

@foozlevazquez
Created March 19, 2015 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foozlevazquez/7c51f7ba3977f2f85a2b to your computer and use it in GitHub Desktop.
Save foozlevazquez/7c51f7ba3977f2f85a2b to your computer and use it in GitHub Desktop.
golang immutable strings
package main
import (
"fmt"
)
func main() {
s1 := "foo"
b1 := []byte(s1)
b1[0] = 'b'
s2 := string(b1)
b1[0] = 'z'
s3 := string(b1)
for i, _ := range b1{
b1[i] = 0
}
fmt.Println(b1, s1, s2, s3)
}
// Prints [0, 0, 0], foo, boo, zoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment