Skip to content

Add to_i to String #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ module String
Erlang.binary_to_atom(self, 'utf8)
end

% Returns the integer representation of this string if it is a valid integer.
def to_i
Erlang.list_to_integer(to_char_list)
end

% Returns a copy of the original string with all lowercase letters replaced with their uppercase counterparts.
def upcase
Erlang.string.to_upper(to_char_list).to_bin
Expand Down
6 changes: 6 additions & 0 deletions test/elixir/string_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ three
"Hello" = "Hello".to_str
end

def to_i_test
0 = "0".to_i
1 = "1".to_i
93402 = "093402".to_i
end

def inspect_test
[34,102,92,110,111,34] = "f\no".inspect.to_char_list

Expand Down