# Check if an array with strings and floating contains a string

**URL:** <https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800>\
**Category:** New to Julia\
**Tags:** array\
**Created:** [June 12, 2021, 3:32pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800 "2021-06-12T15:32:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GAiello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gaiello/32/25984_2.png) [@GAiello](https://discourse.julialang.org/u/GAiello)\
**Post date:** [June 12, 2021, 3:32pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800/1 "2021-06-12T15:32:12Z")

</div>

Hello Everybody,

Let’s say I have a 2-element array containing one floating and a string, something like

```julia
2-element Array{Any,1}:
  "0 0"
 1

```

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

Best

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [June 12, 2021, 3:38pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800/2 "2021-06-12T15:38:08Z")

</div>

The following should work:

```julia
"0 0" in array

```

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [June 12, 2021, 3:47pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800/3 "2021-06-12T15:47:49Z")

</div>

Or, in the case that you don’t know the exact string and want to know if there just is a String:

```julia
julia> String in typeof.(array)
true

```

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 12, 2021, 4:22pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800/4 "2021-06-12T16:22:22Z")

</div>

Or `any(isa.(array, String))` (which potentially does fewer type checks)

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 12, 2021, 4:51pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800/5 "2021-06-12T16:51:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [June 12, 2021, 5:42pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800/6 "2021-06-12T17:42:42Z")

</div>

Perhaps this is the fastest:

```julia
any( x -> isa(x,String), array )

```

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 12, 2021, 6:27pm UTC](https://discourse.julialang.org/t/check-if-an-array-with-strings-and-floating-contains-a-string/62800/7 "2021-06-12T18:27:47Z")

</div>

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:

> <https://github.com/JuliaLang/julia/pull/36759>
>
> This PR adds \`===(x)\`, \`!==(x)\`, and \`isa(T)\` that creates a \`Fix2\` like \`isequa…l\` etc. For \`===(x)\` and \`isa(T)\`, it looks like I needed to add tfuncs.
> 
> fix #36163
> fix #32018

)
