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