문제

How would I go about finding if a sub-bitstring is present with another bitstring in Elixir? I need to verify that bitstring X exists somewhere within bitstring Y for testing purposes. Is there a simple way to do this with existing functions?

x = "bar"
y = "foo bar baz"
some_substring_function(x, y)

with some_substring_function returning a truthy value.

Thanks in advance!

도움이 되었습니까?

해결책

You can use the =~ operator:

iex> "hello world" =~ "hello"
true

The String module also has some convenience functions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top