logo

How to Check if a Specific String is Contained in Julia 📂Julia

How to Check if a Specific String is Contained in Julia

Code

julia> contains("qwerty", "er")
true

julia> contains("qwerty", "et")
false

julia> contains("qwerty", r"q?")
true

contains(haystack::AbstractString, needle)

  • Returns a boolean indicating whether needle is contained in haystack. needle can include regular expressions, such as r"...".

Note that ‘haystack’ means a hay pile, referring to the idiom “a needle in a haystack”.

Environment

  • OS: Windows
  • julia: v1.6.2