I mean a string is blank if it's empty or contains whitespaces only. For example, ""
, " "
and "\n"
are all blank.
In Rails, we have the .blank?
method.
Is there something similar in Elixir (or in the Phoenix Framework)?
String. trim/1 seems to do the trick as of Elixir 1.3. 0. strip still works, but it was soft deprecated in the 1.3.
Strings in Elixir are inserted between double quotes, and they are encoded in UTF-8.
String.trim/1 seems to do the trick as of Elixir 1.3.0.
strip
still works, but it was soft deprecated in the 1.3.0 release and it isn't listed in the String docs.
There is String.strip/1 which will convert your 3 examples to ""
which you can compare against.
iex(4)> String.strip("\n") == "" true iex(5)> String.strip("") == "" true iex(6)> String.strip(" ") == "" true
There was an issue about it https://github.com/elixir-lang/elixir/pull/2707
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With