Cldr Numbers v0.2.1 Cldr.Number.String View Source

String helper functions

Link to this section Summary

Functions

Split a string up into fixed size chunks

Replace any non-latin1 characters with a ?

Replaces characters with a string hex representation

Returns a regex which matches all latin1 characters

Returns a regex which matches all non-latin1 characters

Pad a a string (representing a number) with leading “0”‘s to the specified length

Pad a a string (representing a number) with trailing “0”‘s to the specified length

Link to this section Functions

Link to this function chunk_string(string, size, direction \\ :forward) View Source
chunk_string(String.t(), integer(), :forward | :reverse) :: [String.t()]

Split a string up into fixed size chunks.

Returns a list of strings the size of size plus potentially one more chunk at the end that is the remainder of the string after chunking.

Examples

iex> Cldr.Number.String.chunk_string("This is a string", 3)
["Thi", "s i", "s a", " st", "rin", "g"]

iex> Cldr.Number.String.chunk_string("1234", 4)
["1234"]

iex> Cldr.Number.String.chunk_string("1234", 3)
["123","4"]

iex> Cldr.Number.String.chunk_string("1234", 3, :reverse)
["1", "234"]

Replace any non-latin1 characters with a ?

Replaces characters with a string hex representation

Returns a regex which matches all latin1 characters

Returns a regex which matches all non-latin1 characters

Link to this function pad_leading_zeros(number_string, count) View Source
pad_leading_zeros(String.t(), integer()) :: String.t()

Pad a a string (representing a number) with leading “0”‘s to the specified length.

  • number is a string representation of a number

  • count is the final length required of the string

Link to this function pad_trailing_zeros(number_string, count) View Source
pad_trailing_zeros(String.t(), integer()) :: String.t()

Pad a a string (representing a number) with trailing “0”‘s to the specified length.

  • number is a string representation of a number

  • count is the final length required of the string