HomeManualTopicsTypesSymbols

std_types::string/std::truncate_before

returns the substring starting with the specified expression

Parameters

str
the string to truncate
expr
the expression to look for
nth (default: 1)
look for the nth occurrence of *expr* instead for the first one

Results

None

Description

If the specified expression is found within the string the substring starting with the expression is returned. Otherwise the string is returned unaltered.

If nth is specified then the nth occurence of the expression expr is looked for. If there are not at least n matches for expr within str then the string is returned unaltered.

A very similar function is std_types::string/std::from. It behaves differently only when the expression is not found.

Example

$identifier "std::truncate_before" $last_part identifier .truncate_before. "::" println! last_part

Output

::truncate_before

Example

$identifier "std::truncate_before" $first_part identifier .truncate_before. '.' println! '[' first_part ']'

Output

[std::truncate_before]

Topic

Strings

Implements

std::truncate_before returns the substring starting with the specified expression

See also

std_types::string/std::from returns the substring starting with the specified expression
std_types::string/std::between returns the substring between two expressions
std_types::string/std::until returns the substring until (including) the specified expression
std_types::string/std::until returns the substring until (including) the specified expression