OK, this is fascinating. It happens that I might need to match at any point in the string, so String.ends_with?/2 might not work, but I am much more interested in what you’ve done with the variable by wrapping it in <<>>.
iex(1)> <<first::utf8, rest::binary>> = "string"
"string"
iex(2)> first
115
iex(3)> <<first::utf8>>
"s"
iex(4)> first == "s"
false
iex(5)> <<first::utf8>> == "s"
true
iex(6)> ?s
115
iex(7)> <<?s>>
"s"
This is kind of crazy. It obviously solves my problem, but what is happening here? I clearly don’t fully understand what Elixir strings are. Is Elixir actually converting between a charlist and a binary when I add <<>>? Or is it simply that no conversion is needed, because a charlist wrapped in <<>> is all a binary is? Is there a difference between what I’ve done here and calling Kernel.to_string/1?






















