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

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -