Created
September 29, 2010 13:19
-
-
Save gregworley/602731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// concatenate arrays | |
func stringConcatenate(x, y []string) []string { | |
result := make([]string, len(x) + len(y)) | |
i := 0 | |
for ; i < len(x); i++ { | |
result[i] = x[i] | |
} | |
for j := 0; i < len(x) + len(y); i++ { | |
result[i] = y[j] | |
j++ | |
} | |
return result | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// more idiomatic concatenate slices | |
func concat(a, b []string) []string { | |
c := make([]string, len(a) + len(b)) | |
copy(c[:len(a)], a) | |
copy(c[len(a):], b) | |
return c | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//So to concatenate two strings, using vector package I'd do?: | |
a := []string{"one", "two", "three"} | |
b := []string{"four", "five"} | |
var c vector.StringVector | |
av := vector.StringVector(a) | |
bv := vector.StringVector(b) | |
c.AppendVector(&av) | |
c.AppendVector(&bv) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python 3.1 | |
x = 'hello' | |
y = 'world' | |
print(x + " " + y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking at concatenating strings in python and golang in a golang-nuts discussion ( http://groups.google.com/group/golang-nuts/browse_thread/thread/9d3478bec3c7c68d/dc9d1c11ac2c1a51#dc9d1c11ac2c1a51 )