Slice a string using index positions in Elixir
elixir, string
Solution
You can use `String.slice/2`:
iex(1)> String.slice("Sergio", 1..-1)
"ergio"
iex(2)> String.slice("Sergio", 0..-3)
"Serg"
Problem
In Ruby, I can go: ``` "Sergio"[1..-1] #> "ergio" ``` Doing the same in Elixir gives a runtime error: ``` iex(1)> "Sergio"[1..-1] ** (CompileError) iex:1: the Access syntax and calls to Access.get/2 are not available for the value: "Sergio" ``` Also tried: ``` iex(1)> String.slice("Sergio", 1, -1) ** (FunctionClauseError) no function clause matching in String.slice/3 (elixir) lib/string.ex:1471: String.slice("Sergio", 1, -1) ``` How can I get a substring from a string in Elixir?