Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ch05-strings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Enter width > 3.5
/bin/elixir/lib/iex/lib/iex/server.ex:19: IEx.Server.do_loop/1
----

In this étude, you will use _regular expressions_ to make sure that input is numeric and to distinguish integers from floating point numbers. You need to do this because +binary_to_float/1+ will not accept a string like +"1812"+ as an argument. If you aren't familiar with regular expressions, there is a short summary in <<APPENDIXB>>.
In this étude, you will use _regular expressions_ to make sure that input is numeric and to distinguish integers from floating point numbers. You need to do this because +String.to_float/1+ will not accept a string like +"1812"+ as an argument. If you aren't familiar with regular expressions, there is a short summary in <<APPENDIXB>>.

The function you will use is the +Regex.match?/2+. It takes a regular expression pattern as its first argument and a string as its second argument. The function returns +true+ if the pattern matches the string, +false+ otherwise. Here are some examples in IEx.

Expand Down
4 changes: 2 additions & 2 deletions code/ch05-02/ask_area.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ defmodule AskArea do
input_str = String.strip(input)
cond do
Regex.match?(~r/^[+-]?\d+$/, input_str) ->
binary_to_integer(input_str)
String.to_integer(input_str)
Regex.match?(~r/^[+-]?\d+\.\d+([eE][+-]?\d+)?$/, input_str) ->
binary_to_float(input_str)
String.to_float(input_str)
true -> :error
end
end
Expand Down
4 changes: 2 additions & 2 deletions code/ch05-03/dates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Dates do

def date_parts(date_str) do
[y_str, m_str, d_str] = String.split(date_str, ~r/-/)
[binary_to_integer(y_str), binary_to_integer(m_str),
binary_to_integer(d_str)]
[String.to_integer(y_str), String.to_integer(m_str),
String.to_integer(d_str)]
end
end
4 changes: 2 additions & 2 deletions code/ch06-02/dates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Dates do

def date_parts(date_str) do
[y_str, m_str, d_str] = String.split(date_str, ~r/-/)
[binary_to_integer(y_str), binary_to_integer(m_str),
binary_to_integer(d_str)]
[String.to_integer(y_str), String.to_integer(m_str),
String.to_integer(d_str)]
end
end
4 changes: 2 additions & 2 deletions code/ch06-02b/dates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Dates do

def date_parts(date_str) do
[y_str, m_str, d_str] = String.split(date_str, ~r/-/)
[binary_to_integer(y_str), binary_to_integer(m_str),
binary_to_integer(d_str)]
[String.to_integer(y_str), String.to_integer(m_str),
String.to_integer(d_str)]
end
end
4 changes: 2 additions & 2 deletions code/ch08-04/dates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Dates do

def date_parts(date_str) do
[y_str, m_str, d_str] = String.split(date_str, ~r/-/)
[binary_to_integer(y_str), binary_to_integer(m_str),
binary_to_integer(d_str)]
[String.to_integer(y_str), String.to_integer(m_str),
String.to_integer(d_str)]
end
end
4 changes: 2 additions & 2 deletions code/ch10-02/bank.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ defmodule Bank do
input_str = String.strip(input)
cond do
Regex.match?(~r/^[+-]?\d+$/, input_str) ->
binary_to_integer(input_str)
String.to_integer(input_str)
Regex.match?(~r/^[+-]?\d+\.\d+([eE][+-]?\d+)?$/, input_str) ->
binary_to_float(input_str)
String.to_float(input_str)
true -> :error
end
end
Expand Down
2 changes: 1 addition & 1 deletion code/ch11-01/phone_ets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule PhoneEts do

defp gregorianize(str, delimiter) do
list_to_tuple(for item <- String.split(str, delimiter), do:
binary_to_integer(item))
String.to_integer(item))
end

@doc """
Expand Down