How to trim a string

I am getting a variable that holds a string. I want to trim it to first "?" sign, so I can pass it futher.

For example, I want to always transfrom x = /example?idontwantthis to x = /example?

>Solution :

I’d go with String.split/3

"/example?idontwantthis" |> String.split("?") |> hd()
#⇒ "/example"

Leave a Reply