It is not documented, but it does not trim your string, what is does is to parse the first integers it finds, and returns the remainder of the string as the second element of the tuple.
iex> Integer.parse("2ABC") {2, "ABC"} On Mon, 8 Mar 2021 07:04:54 -0800 (PST) Izzy Elwyn <izzy.el...@gmail.com> wrote: > Hello, all! > > I recently had an issue with consistency in the behavior of > Integer.parse/2 where it handles trailing whitespace, but fails to > handle leading whitespace. > > Example: > Integer.parse("12 ") > {12, " "} > Integer.parse(" 12") > :error > > Because the trailing whitespace was handled, I had operated under the > false assumption that the function would properly trim whitespace > (both trailing *and* leading) and return a valid integer. For this > reason, it look me a bit to track down leading whitespace as the > root-cause of a production issue. > > I'd like to propose trimming whitespace as an enhancement to the > functionality of Integer.parse/2 to improve consistency in its > behavior. > > ~ Izzy > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/60463f1d.1c69fb81.c0d57.80d5SMTPIN_ADDED_MISSING%40gmr-mx.google.com.