How to check if a string is blank in Elixir

Van Huy picture Van Huy · Dec 3, 2015 · Viewed 19.8k times · Source

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)?

Answer

Jason Harrison picture Jason Harrison · Jun 26, 2016

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.