Next: , Previous: , Up: strings   [Contents][Index]


14.2 Inspecting a string

Function: mbfl_string_length string

Print an integer representing the length of string. The argument string can be an empty string.

Function: mbfl_string_length_equal_to length string

Return successfully if string has length equal to length. The argument length must be a non-negative integer; the argument string can be an empty string.

Function: mbfl_string_is_empty string

Return successfully if string is empty.

Function: mbfl_string_is_not_empty string

Return successfully if string is not empty.

Function: mbfl_string_index string index
Function: mbfl_string_index_var _RV string index

Select a character from a string. Echo to stdout the selected character. If the index is out of range: the empty string is echoed to stdout, that is: a newline is echoed to stdout.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

mbfl_string_index abcdefghilm  0        -| a
mbfl_string_index abcdefghilm  4        -| e
mbfl_string_index abcdefghilm 10        -| m
mbfl_string_index abcdefghilm 11        -| <empty string>

local _RV
mbfl_string_index_var _RV abcdefghilm 0
"$_RV" ⇒ a
Function: mbfl_string_first string char
Function: mbfl_string_first string char begin
Function: mbfl_string_first_var _RV string char
Function: mbfl_string_first_var _RV string char begin

Search characters in a string. Arguments: string, the target string; char, the character to look for; begin, optional, the index of the character in the target string from which the search begins (defaults to zero).

If the character is found: print an integer representing the index of the last occurrence of char in string, then return with status zero. If the character is not found: print nothing and return with status one.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

mbfl_string_first abcdefghilm d         -| 3
mbfl_string_first abcdefghilm a         -| 0
mbfl_string_first abcdefghilm m         -| 10
mbfl_string_first abcdefghilm X         -| <empty string>

mbfl_string_first abcdeabcde  a 3       -| 5
mbfl_string_first abcdeabcde  e 5       -| 9
mbfl_string_first abcdeabcde  e 4       -| 4

local _RV
mbfl_string_first_var _RV abcdefghilm d
"$_RV" ⇒ 3
Function: mbfl_string_last string char
Function: mbfl_string_last string char begin
Function: mbfl_string_last_var _RV string char
Function: mbfl_string_last_var _RV string char begin

Search characters in a string starting from the end. Arguments: string, the target string; char, the character to look for; begin, optional, the index of the character in the target string from which the search begins (defaults to zero).

If the character is found: print an integer representing the index of the last occurrence of char in string, then return with status zero. If the character is not found: print nothing and return with status one.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

mbfl_string_last abcdefghilm d          -| 3
mbfl_string_last abcdefghilm a          -| 0
mbfl_string_last abcdefghilm m          -| 10
mbfl_string_last abcdefghilm X          -| <empty string>

mbfl_string_last abcdefghilm a 3        -| 0
mbfl_string_last abcdeabcde  a 7        -| 5
mbfl_string_last abcdeabcde  e 7        -| 4
mbfl_string_last abcdeabcde  e 4        -| 4

local _RV
mbfl_string_last_var _RV abcdefghilm d
"$_RV" ⇒ 3
Function: mbfl_string_range string begin
Function: mbfl_string_range string begin end
Function: mbfl_string_range_var _RV string begin
Function: mbfl_string_range_var _RV string begin end

Extract a range of characters from a string. Arguments: string, the source string; begin, the index of the first character in the range; end, optional, the index of the character past the last in the range, this character is not extracted.

end defaults to the string length; if the parameter end is set to the lowercase string end or the uppercase string END: the end index is set to the string length.

Echo to stdout the selected range of characters, which may be the empty string.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

mbfl_string_range abcdefghilm 0 end     -| abcdefghilm
mbfl_string_range abcdefghilm 0         -| abcdefghilm
mbfl_string_range abcdefghilm 0 4       -| abcd
mbfl_string_range abcdefghilm 4 end     -| efghilm

local _RV
mbfl_string_range_var _RV abcdefghilm 4 end
"$_RV" ⇒ efghilm

Next: , Previous: , Up: strings   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.