What is the best way to trim characters?

I want to trim “s” from this sentence.


Then, I use String.trim/2 to trim “s”.

iex(1)> a = "aassddaa"
iex(2)> b = String.trim(a, "s")

It does not work.
But “a” can be trimmed.

iex(3)> c = String.trim(a, "a")

Why does it work like that?

Because trim removes trailing symbols.
You need String.replace/3:

> String.replace("aassddaa", "s", "")

Thank you for the quick answer!

@Papillon6814 Please read documentation for:

  1. String.replace/4
  2. String.replace_leading/3
  3. String.replace_prefix/3
  4. String.replace_suffix/3
  5. String.replace_trailing/3
  6. String.trim/2
  7. String.trim_leading/2
  8. String.trim_trailing/2

Trimming in this case just removes characters from the start and the end, not from anywhere inside the string.