Cldr v0.0.19 Cldr.Number.String

String helper functions

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

Functions

chunk_string(string, size, direction \\ :forward)
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"]
clean(string)

Replace any non-latin1 characters with a ?

hex_string(string)

Replaces characters with a string hex representation

latin1()

Returns a regex which matches all latin1 characters

not_latin1()

Returns a regex which matches all non-latin1 characters

pad_leading_zeros(number_string, count)
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

pad_trailing_zeros(number_string, count)
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