2

I'm writing a function to replace all underscores in a string with dashes. For example:

underscores_to_dashes("erlang_is_great") = "erlang-is-great"

At the moment I'm using the following function:

underscores_to_dashes(String) ->
    [case Char of 95 -> 45; _ -> Char end || Char <- String].

In this implementation it's not obvious which character is being replaced with which and I have to use list comprehension and a case statement.

Is there a simpler way to implement such functionality? Perhaps I'm missing some in-built erlang function?

Sergey Ovchinnik
  • 472
  • 4
  • 16

0 Answers0