Stream: helpdesk (published)

Topic: Strings in if statements


view this post on Zulip brett knoss (May 29 2021 at 23:29):

If I try to do the following

i=["string"]
for j in i
        if i == i[j]
                print(i[j])
         end
end

it says I'm using a string as an index. How do I test if a string is in array?

view this post on Zulip mbaz (May 29 2021 at 23:37):

julia> i = ["string1", "string2"]
2-element Vector{String}:
 "string1"
 "string2"

julia> "string1" in i
true

julia> "string3" in i
false

view this post on Zulip brett knoss (May 30 2021 at 00:24):

Ok, thanks!


Last updated: Nov 06 2024 at 04:40 UTC