arose said:
How to I mix variables and strings together.
In vb I use the & for example.
firstthree="abc"
firstsix=firstthree & "def"
For many String concatenations, do *not* use the + operator, rather
collect all the small strings to be concatenated in an array and use
.join("")
-----
n=10000
t = Time.new
str = ""
(0).upto(n) { str += "somestring"}
p Time.new-t
t = Time.new
str = []
(0).upto(n) { str.push("somestring") }
str = str.join("")
p Time.new-t
-----
yields
0.879806
0.038133
The reason is that whenever a string is appended via +, new space must
be made availabe in memory and that leads to subsequent copying of the
whole string. (This is what I assume, I have not looked at the ruby
source code...)
ciao,
Oliver