Search code examples
erlangerl

How do I remove a character from a list or string in Erlang?


How do I remove the character / from this list (or call it a string)

List = "/hi"

Solution

  • Because Erlang variables are immutable and

    List = "/hi".
    

    binds List to the expression "\hi", you cannot simply remove anything from List; in fact, you cannot alter List in any way as long as it remains bound.

    What you can do instead is bind another variable, called T below, to the tail of List, like so:

    1> List = "/hi".
    "/hi"
    2> T=tl(List).
    "/hi"
    3> T.
    "hi"