Hello.
I want to trim “s” from this sentence.
"aassddaa"
Then, I use String.trim/2
to trim “s”.
iex(1)> a = "aassddaa"
"aassddaa"
iex(2)> b = String.trim(a, "s")
"aassddaa"
It does not work.
But “a” can be trimmed.
iex(3)> c = String.trim(a, "a")
"ssdd"
Why does it work like that?
fuelen
2
Because trim removes trailing symbols.
You need String.replace/3
:
> String.replace("aassddaa", "s", "")
"aaddaa"
4 Likes
Thank you for the quick answer!
Eiji
4
3 Likes
Trimming in this case just removes characters from the start and the end, not from anywhere inside the string.