View Source Moar.String (Moar v0.1.0)
String-related functions
Link to this section Summary
Functions
Convert strings and atoms to dash-case (kebab-case) and trims leading and trailing non-alphanumeric characters.
Truncate s
to max_length
by removing the middle of the string
Compares the two binaries in constant-time to avoid timing attacks. See: http://codahale.com/a-lesson-in-timing-attacks/
Replace consecutive whitespace characters with a single space
Add surrounder
to the beginning and end of s
Add prefix
to the beginning of s
and suffix
to the end
Convert a string to an integer. Returns nil
if the argument is nil
or empty string
Like to_integer/1
but with options
Like String.trim/1
but returns nil
if the argument is nil
Truncates s
at the last instance of at
, causing the string to be at most limit
characters.
Link to this section Functions
Convert strings and atoms to dash-case (kebab-case) and trims leading and trailing non-alphanumeric characters.
The following all get converted to "foo"
: "foo"
, "FOO"
, :foo
.
The following all get converted to "foo-bar"
: "foo-bar"
, :foo_bar
, " fooBar "
, " ?foo ! bar "
Truncate s
to max_length
by removing the middle of the string
Compares the two binaries in constant-time to avoid timing attacks. See: http://codahale.com/a-lesson-in-timing-attacks/
Replace consecutive whitespace characters with a single space
Add surrounder
to the beginning and end of s
Add prefix
to the beginning of s
and suffix
to the end
Convert a string to an integer. Returns nil
if the argument is nil
or empty string
Like to_integer/1
but with options:
:lenient
option removes non-digit characters firstdefault:
option specifies a default in cases
is nil
Like String.trim/1
but returns nil
if the argument is nil
Truncates s
at the last instance of at
, causing the string to be at most limit
characters.
iex> Moar.String.truncate_at("I like apples. I like bananas. I like cherries.", ".", 35)
"I like apples. I like bananas."