Elixir Prelude v0.2.1 Prelude.String

Functions operating on strings.

Summary

Functions

Returns the first code point in the string, or nil if str is empty

Checks if a string is the string representation of an integer

Chops off the first codepoint, and returns the rest of the string

Safely convert strings to integers

Functions

head(str)

Returns the first code point in the string, or nil if str is empty

Example:

iex> Prelude.String.head("4545")
"4"

iex> Prelude.String.head("")
nil
is_integer?(str)

Checks if a string is the string representation of an integer

Example:

iex> Prelude.String.is_integer?("34545")
true

iex> Prelude.String.is_integer?("a34545")
false
tail(str)

Chops off the first codepoint, and returns the rest of the string.

Returns an empty string if String.length(str) == 1, and nil if string is empty.

Example:

iex> Prelude.String.tail("4545")
"545"

iex> Prelude.String.tail("")
nil
to_int(y)

Safely convert strings to integers

Leaves integers alone, and defaults to 0 on error

Example:

iex> Prelude.String.to_int("4545")
4545

iex> Prelude.String.to_int(4545)
4545