How are stripes commas from a string in Elixir?

I wonder how to remove commas from a given string. My attempt was

st = "1,2,3" String.strip(st, ?,) #=> "1,2,3" 

What am I doing wrong?

+6
source share
2 answers

String.strip/2 removes only the characters at the beginning and end of a line. I believe you are looking for String.replace/4 . Use it like this:

 String.replace("1,2,3", ",", "") 
+11
source

You can also do something like this:

 st |> String.split(",") |> Enum.join 

Of course, it is best to use a standard tool, but then this is an alternative.

0
source

All Articles