I am trying to swap the order of a string but haven’t had much luck getting it to work.
Input:
7F66E4C95D6020B1F32A9B55F383D9E7
Desired Output:
f7664e9cd506021b3fa2b9553f389d7e
I am trying to swap the order of a string but haven’t had much luck getting it to work.
Input:
7F66E4C95D6020B1F32A9B55F383D9E7
Desired Output:
f7664e9cd506021b3fa2b9553f389d7e
Hello and welcome…
s = "7F66E4C95D6020B1F32A9B55F383D9E7"
s
|> String.downcase()
|> String.graphemes()
|> Enum.chunk_every(2)
|> Enum.reduce(<<>>, fn [x, y], acc -> acc <> y <> x end)
"f7664e9cd506021b3fa2b9553f389d7e"
Brilliant. Thank you!
Other options:
A simple for
:
for << <<a, b>> <- s >>, into: "" do
<<b, a>>
end
or via regex:
String.replace(s, ~r/(\w)(\w)/, "\\2\\1")