Julia: Search string vector for a character and add that character -
i want detect if character exists in vector of strings , if not add end.
mystrings = ["asfs", "asfsaf", "sfas.sdg", "dsgsd", "sdgsd."] i=1:length(mystrings) if !contains(mystrings[i],".") mystrings[i] = mystrings[i] * "." end end
the above works. writing more ask, if should have instead used kind of broadcasting or if ideal solution.
i don't think there's wrong code posted. broadcasting solution might like
mystrings .= (x->contains(x, '.') ? x : x*".").(mystrings)
or if prefer map style
map!(x->contains(x, '.') ? x : x*".", mystrings, mystrings)
both (and solution well) avoid allocation modifying array.
Comments
Post a Comment