In Go, a string
is a primitive type, which means it is read-only, and every manipulation of it will create a new string. 在Go中, string
是基本类型,这意味着它是只读的,而且对它的每次操做都将建立一个新字符串。 spa
So if I want to concatenate strings many times without knowing the length of the resulting string, what's the best way to do it? 所以,若是我想在不知道结果字符串长度的状况下屡次链接字符串,那么最好的方法是什么? .net
The naive way would be: 天真的方式是: code
s := "" for i := 0; i < 1000; i++ { s += getShortStringFromSomewhere() } return s
but that does not seem very efficient. 但这彷佛不是颇有效。 ip