Let’s say I have a 2-element array containing one floating and a string, something like
I want to check whether the array contains the string “0 0”. I tried
isassigned(), but it does not work with strings. Do you have any suggestions?
Thank you for your time
The following should work:
"0 0" in array
Or, in the case that you don’t know the exact string and want to know if there just is a String:
julia> String in typeof.(array)
any(isa.(array, String)) (which potentially does fewer type checks)
Actually, benchmarking it, my method has a slightly worse best case and a much worse worst case. But for a majority of cases it’s faster. So I guess I don’t know.
Perhaps this is the fastest:
any( x -> isa(x,String), array )
It is indeed. By two orders of magnitude. I keep forgetting about that version of the
any family of functions.
(also, looking forward to this, if it ever happens: