Initialize string array
s = SubString{String}["Julia", "uses", "multiple", "dispatch", "as", "a", "paradigm,", "making", "it", "easy", "to", "express", "many", "object-oriented", "and", "functional", "programming", "patterns.", "The", "standard", "library", "provides", "..."]
I try to replace a certain character in all strings of the array
replace.(data, "." => "")
yields an error
ERROR: DimensionMismatch("arrays could not be broadcast to a common size")
Stacktrace:
[1] _bcs1 at .\broadcast.jl:439 [inlined]
[2] _bcs at .\broadcast.jl:433 [inlined]
[3] broadcast_shape at .\broadcast.jl:427 [inlined]
[4] combine_axes at .\broadcast.jl:422 [inlined]
[5] instantiate at .\broadcast.jl:266 [inlined]
[6] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(replace),Tuple{Array{SubString{String},1},Array{String,1}}}) at .\broadcast.jl:748
[7] top-level scope at none:0
but
(t->replace(t, "a"=>"x")).(s)
works as expected:
23-element Array{String,1}:
"Julix"
"uses"
"multiple"
"dispxtch"
"xs"
"x"
"pxrxdigm,"
"mxking"
"it"
"exsy"
"to"
"express"
"mxny"
"object-oriented"
"xnd"
"functionxl"
"progrxmming"
"pxtterns."
"The"
"stxndxrd"
"librxry"
"provides"
"..."
I expected it to automatically broadcast it over the array. Why doesn’t it work like that?