Back to Atomvm

Module string

main-apidocs-erlang-estdlib-string.md

latest5.4 KB
Original Source

Module string

An implementation of the Erlang/OTP string interface.

Description

This module implements a strict subset of the Erlang/OTP string interface.

Function Index

| find/2 | Equivalent to find(String, SearchPattern, leading). | | find/3 | | | jaro_similarity/2 | Calculate the Jaro similarity between two strings (stub implementation). | | length/1 | Return the length of the string in characters. | | split/2 | Equivalent to split(String, Pattern, leading). | | split/3 | Splits String where SearchPattern is encountered and return the remaining parts. | | to_lower/1 | Convert string or character to uppercase. | | to_upper/1 | Convert string or character to uppercase. | | trim/1 | Equivalent to trim(String, both). | | trim/2 | Returns a string, where leading or trailing, or both, whitespace has been removed. |

Function Details

find/2

find(String::unicode:chardata(), SearchPattern::unicode:chardata()) -> unicode:chardata() | nomatch

String: string to search in
SearchPattern: pattern to search

returns: remainder of String starting from first occurrence of SearchPattern or nomatch if SearchPattern cannot be found in String

Equivalent to find(String, SearchPattern, leading).

find/3

find(String::unicode:chardata(), SearchPattern::unicode:chardata(), Direction::leading | trailing) -> unicode:chardata() | nomatch

String: string to search in
SearchPattern: pattern to search
Direction: direction to search, leading or trailing

returns: remainder of String starting from first or last occurrence of SearchPattern or nomatch if SearchPattern cannot be found in String

jaro_similarity/2

jaro_similarity(String1::unicode:chardata(), String2::unicode:chardata()) -> float()

String1: first string to compare
String2: second string to compare

Calculate the Jaro similarity between two strings (stub implementation).

This is a stub implementation that always returns 0.0, used for compatibility.

length/1

length(String::unicode:chardata()) -> non_neg_integer()

String: string to compute the length of

Return the length of the string in characters.

split/2

split(String::unicode:chardata(), Pattern::unicode:chardata()) -> [unicode:chardata()]

String: a string to split
Pattern: the search pattern to split at

returns: chardata

Equivalent to split(String, Pattern, leading).

split/3

split(String::unicode:chardata(), Pattern::unicode:chardata(), Where::leading | trailing | all) -> [unicode:chardata()]

String: a string to split
Pattern: the search pattern to split at
Where: position to split (leading, trailing, or all)

returns: chardata

Splits String where SearchPattern is encountered and return the remaining parts.

Where, default leading, indicates whether the leading, the trailing or all encounters of SearchPattern will split String.

Example:

0> string:split("ab..bc..cd", "..").
  ["ab","bc..cd"]
  1> string:split(<<"ab..bc..cd">>, "..", trailing).
  [<<"ab..bc">>,<<"cd">>]
  2> string:split(<<"ab..bc....cd">>, "..", all).
  [<<"ab">>,<<"bc">>,<<>>,<<"cd">>]

to_lower/1

to_lower(Input::string() | char()) -> string() | char()

Input: a string or character to convert

returns: a Character or string

Convert string or character to uppercase.

The specified string or character is case-converted. Notice that the supported character set is ISO/IEC 8859-1 (also called Latin 1); all values outside this set are unchanged

to_upper/1

to_upper(Input::string() | char()) -> string() | char()

Input: a string or character to convert

returns: a Character or string

Convert string or character to uppercase.

The specified string or character is case-converted. Notice that the supported character set is ISO/IEC 8859-1 (also called Latin 1); all values outside this set are unchanged

trim/1

trim(String::string()) -> string() | char()

String: a string or character to trim whitespace

returns: a Character or string

Equivalent to trim(String, both).

trim/2

trim(String::string(), Direction::atom()) -> string() | char()

String: a string or character to trim
Direction: an atom indicating the direction from which to remove whitespace

returns: a Character or string

Returns a string, where leading or trailing, or both, whitespace has been removed.

If omitted, Direction is both.

Example:

1> string:trim("\t Hello \n").
  "Hello"
  2> string:trim(<<"\t Hello \n">>, leading).
  <<"Hello \n">>
  3> string:trim(<<".Hello.\n">>, trailing, "\n.").
  <<".Hello">>