Skip to content

Instantly share code, notes, and snippets.

@gregworley
Created September 29, 2010 13:19
Show Gist options
  • Save gregworley/602731 to your computer and use it in GitHub Desktop.
Save gregworley/602731 to your computer and use it in GitHub Desktop.
// 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
}
// 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
}
//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)
#python 3.1
x = 'hello'
y = 'world'
print(x + " " + y)
@gregworley
Copy link
Author

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment