Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有三个字符串:
first = "test" second = "hello" third = "world"
我想像这样连接它们:
test-hello-world
我尝试使用+:
+
first + "-" + second + "-" + third
但我正在寻找一种在 Ruby 中执行此操作的更好方法。
你可以做:
[first, second, third].join('-')
或者,如果您不关心变量:
%w(test hello world).join('-')
试试这个:
如果它们在一个数组中,您可以使用.join
.join