2016-12-23 15 views
3

私は値の1-dベクトルを持っています。私はコンマで区切られた値を文字列に変換したい。ジュリアにこれをする簡単な方法はありますか? rjuliaでコンマ区切り文字列としてベクトルを折りたたむ

{julia} 
julia> x = [24,122,63,24,83,56,54,175,11,11,24,51,85,92,74,500,80,127,126,59,111,155,132,202,64,164,1301] 

#I want output like this as a string 
#24,122,63,24,83,56,54,175,11,11,24,51,85,92,74,500,80,127,126,59,111,155,132,202,64,164,1301,27 

#I have tried something like this 
[julia> [print(i,",") for i in x] 
24,122,63,24,83,56,54,175,11,11,24,51,85,92,74,500,80,127,126,59,111,155,132,202,64,164,1301,27-element Array{Void,1}: 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 
nothing 

答えて

3

印刷崩壊のようなものは、通常のループと値のほとんどは、(末尾のカンマを排除するために)最後の項目を印刷:

julia> for i in @view x[1:end-1] 
      print(i, ',') 
     end; print(x[end]) 
24,122,63,24,83,56,54,175,11,11,24,51,85,92,74,500,80,127,126,59,111,155,132,202,64,164,1301 

各項目に参加することもできますカンマで反復可能で:単純である。また

julia> print(join(x, ',')) 
24,122,63,24,83,56,54,175,11,11,24,51,85,92,74,500,80,127,126,59,111,155,132,202,64,164,1301 
+2

'join(map(string、x)、 '、')'は私が望むものです。ありがとう – PoisonAlien

+1

@PoisonAlien - 'map'は必要ではないように見えます。あなたは' join(x、 '、') 'を直接行うことができます。 – TigerhawkT3

0

この、:print(string(x)[2:(end - 1)])

関連する問題