stdlib_strings#
See also the specification page: stdlib_strings.
stdlib_strings (module)#
This module implements basic string handling routines.
The specification of this module is available in stdlib_strings.
Interfaces
to_string (interface)#
-
to_string (interface) Format or transfer other types as a string. (Specification: stdlib_strings)
- Procedures:
-
pure module function to_string_r_sp(value, format) -> string# - Arguments:
- valuereal(kind=sp), intent(in)
- formatcharacter(len=*), intent(in), optional
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_r_dp(value, format) -> string# - Arguments:
- valuereal(kind=dp), intent(in)
- formatcharacter(len=*), intent(in), optional
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_c_sp(value, format) -> string# - Arguments:
- valuecomplex(kind=sp), intent(in)
- formatcharacter(len=*), intent(in), optional
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_c_dp(value, format) -> string# - Arguments:
- valuecomplex(kind=dp), intent(in)
- formatcharacter(len=*), intent(in), optional
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_1_i_int8(value) -> string# - Arguments:
- valueinteger(kind=int8), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_2_i_int8(value, format) -> string# - Arguments:
- valueinteger(kind=int8), intent(in)
- formatcharacter(len=*), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_1_i_int16(value) -> string# - Arguments:
- valueinteger(kind=int16), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_2_i_int16(value, format) -> string# - Arguments:
- valueinteger(kind=int16), intent(in)
- formatcharacter(len=*), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_1_i_int32(value) -> string# - Arguments:
- valueinteger(kind=int32), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_2_i_int32(value, format) -> string# - Arguments:
- valueinteger(kind=int32), intent(in)
- formatcharacter(len=*), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_1_i_int64(value) -> string# - Arguments:
- valueinteger(kind=int64), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_2_i_int64(value, format) -> string# - Arguments:
- valueinteger(kind=int64), intent(in)
- formatcharacter(len=*), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
-
pure module function to_string_1_l_lk(value) -> string# - Arguments:
- valuelogical(kind=lk), intent(in)
- Returns:
- stringcharacter(len=1)
-
pure module function to_string_2_l_lk(value, format) -> string# - Arguments:
- valuelogical(kind=lk), intent(in)
- formatcharacter(len=*), intent(in)
- Returns:
- stringcharacter(len=:), allocatable
to_c_char (interface)#
-
to_c_char (interface) Format or transfer other types as a string. (Specification: stdlib_strings)
- Procedures:
strip (interface)#
-
strip (interface) Remove leading and trailing whitespace characters.
Version: experimental
- Procedures:
chomp (interface)#
-
chomp (interface) Remove trailing characters in set from string. If no character set is provided trailing whitespace is removed.
Version: experimental
starts_with (interface)#
-
starts_with (interface) Check whether a string starts with substring or not
Version: experimental
ends_with (interface)#
-
ends_with (interface) Check whether a string ends with substring or not
Version: experimental
slice (interface)#
-
slice (interface) Extracts characters from the input string to return a new string
Version: experimental
- Procedures:
find (interface)#
-
find (interface) Finds the starting index of substring ‘pattern’ in the input ‘string’ [Specifications](link to the specs - to be completed)
Version: experimental
replace_all (interface)#
-
replace_all (interface) Replaces all the occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Version: experimental
padl (interface)#
-
padl (interface) Left pad the input string Specifications: stdlib_strings
padr (interface)#
-
padr (interface) Right pad the input string Specifications: stdlib_strings
count (interface)#
-
count (interface) Returns the number of times substring ‘pattern’ has appeared in the input string ‘string’ Specifications: stdlib_strings
zfill (interface)#
-
zfill (interface) Left pad the input string with zeros. Specifications: stdlib_strings
- Procedures:
join (interface)#
-
join (interface) Joins an array of strings into a single string. The chunks are separated with a space, or an optional user-defined separator. Specifications: stdlib_strings
- Procedures:
Procedures
strip_string (function)#
-
pure function strip_string(string) -> stripped_string Remove leading and trailing whitespace characters.
- Arguments:
- stringtype(string_type), intent(in)
- Returns:
- stripped_stringtype(string_type)
strip_char (function)#
-
pure function strip_char(string) -> stripped_string Remove leading and trailing whitespace characters.
- Arguments:
- stringcharacter(len=*), intent(in)
- Returns:
- stripped_stringcharacter(len=:), allocatable
chomp_string (function)#
-
pure function chomp_string(string) -> chomped_string Remove trailing characters in set from string. Default character set variant where trailing whitespace is removed.
- Arguments:
- stringtype(string_type), intent(in)
- Returns:
- chomped_stringtype(string_type)
chomp_char (function)#
-
pure function chomp_char(string) -> chomped_string Remove trailing characters in set from string. Default character set variant where trailing whitespace is removed.
- Arguments:
- stringcharacter(len=*), intent(in)
- Returns:
- chomped_stringcharacter(len=:), allocatable
chomp_set_string_char (function)#
-
pure function chomp_set_string_char(string, set) -> chomped_string Remove trailing characters in set from string.
- Arguments:
- stringtype(string_type), intent(in)
- setcharacter(len=1), intent(in), dimension(:)
- Returns:
- chomped_stringtype(string_type)
chomp_set_char_char (function)#
-
pure function chomp_set_char_char(string, set) -> chomped_string Remove trailing characters in set from string.
- Arguments:
- stringcharacter(len=*), intent(in)
- setcharacter(len=1), intent(in), dimension(:)
- Returns:
- chomped_stringcharacter(len=:), allocatable
chomp_substring_string_string (function)#
-
pure function chomp_substring_string_string(string, substring) -> chomped_string Remove trailing substrings from string.
- Arguments:
- stringtype(string_type), intent(in)
- substringtype(string_type), intent(in)
- Returns:
- chomped_stringtype(string_type)
chomp_substring_string_char (function)#
-
pure function chomp_substring_string_char(string, substring) -> chomped_string Remove trailing substrings from string.
- Arguments:
- stringtype(string_type), intent(in)
- substringcharacter(len=*), intent(in)
- Returns:
- chomped_stringtype(string_type)
chomp_substring_char_string (function)#
-
pure function chomp_substring_char_string(string, substring) -> chomped_string Remove trailing substrings from string.
- Arguments:
- stringcharacter(len=*), intent(in)
- substringtype(string_type), intent(in)
- Returns:
- chomped_stringcharacter(len=:), allocatable
chomp_substring_char_char (function)#
-
pure function chomp_substring_char_char(string, substring) -> chomped_string Remove trailing substrings from string.
- Arguments:
- stringcharacter(len=*), intent(in)
- substringcharacter(len=*), intent(in)
- Returns:
- chomped_stringcharacter(len=:), allocatable
starts_with_char_char (function)#
-
pure function starts_with_char_char(string, substring) -> match Check whether a string starts with substring or not
- Arguments:
- stringcharacter(len=*), intent(in)
- substringcharacter(len=*), intent(in)
- Returns:
- matchlogical
starts_with_string_char (function)#
-
elemental function starts_with_string_char(string, substring) -> match Check whether a string starts with substring or not
- Arguments:
- stringtype(string_type), intent(in)
- substringcharacter(len=*), intent(in)
- Returns:
- matchlogical
starts_with_char_string (function)#
-
elemental function starts_with_char_string(string, substring) -> match Check whether a string starts with substring or not
- Arguments:
- stringcharacter(len=*), intent(in)
- substringtype(string_type), intent(in)
- Returns:
- matchlogical
starts_with_string_string (function)#
-
elemental function starts_with_string_string(string, substring) -> match Check whether a string starts with substring or not
- Arguments:
- stringtype(string_type), intent(in)
- substringtype(string_type), intent(in)
- Returns:
- matchlogical
ends_with_char_char (function)#
-
pure function ends_with_char_char(string, substring) -> match Check whether a string ends with substring or not
- Arguments:
- stringcharacter(len=*), intent(in)
- substringcharacter(len=*), intent(in)
- Returns:
- matchlogical
ends_with_string_char (function)#
-
elemental function ends_with_string_char(string, substring) -> match Check whether a string ends with substring or not
- Arguments:
- stringtype(string_type), intent(in)
- substringcharacter(len=*), intent(in)
- Returns:
- matchlogical
ends_with_char_string (function)#
-
elemental function ends_with_char_string(string, substring) -> match Check whether a string ends with substring or not
- Arguments:
- stringcharacter(len=*), intent(in)
- substringtype(string_type), intent(in)
- Returns:
- matchlogical
ends_with_string_string (function)#
-
elemental function ends_with_string_string(string, substring) -> match Check whether a string ends with substring or not
- Arguments:
- stringtype(string_type), intent(in)
- substringtype(string_type), intent(in)
- Returns:
- matchlogical
slice_string (function)#
-
elemental function slice_string(string, first, last, stride) -> sliced_string Extract the characters from the region between ‘first’ and ‘last’ index (both inclusive) of the input ‘string’ by taking strides of length ‘stride’ Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- firstinteger, intent(in), optional
- lastinteger, intent(in), optional
- strideinteger, intent(in), optional
- Returns:
- sliced_stringtype(string_type)
slice_char (function)#
-
pure function slice_char(string, first, last, stride) -> sliced_string Extract the characters from the region between ‘first’ and ‘last’ index (both inclusive) of the input ‘string’ by taking strides of length ‘stride’ Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- firstinteger, intent(in), optional
- lastinteger, intent(in), optional
- strideinteger, intent(in), optional
- Returns:
- sliced_stringcharacter(len=:), allocatable
find_string_string (function)#
-
elemental function find_string_string(string, pattern, occurrence, consider_overlapping) -> res Returns the starting index of the ‘occurrence’th occurrence of substring ‘pattern’ in input ‘string’ Returns an integer
- Arguments:
- stringtype(string_type), intent(in)
- patterntype(string_type), intent(in)
- occurrenceinteger, intent(in), optional
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
find_string_char (function)#
-
elemental function find_string_char(string, pattern, occurrence, consider_overlapping) -> res Returns the starting index of the ‘occurrence’th occurrence of substring ‘pattern’ in input ‘string’ Returns an integer
- Arguments:
- stringtype(string_type), intent(in)
- patterncharacter(len=*), intent(in)
- occurrenceinteger, intent(in), optional
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
find_char_string (function)#
-
elemental function find_char_string(string, pattern, occurrence, consider_overlapping) -> res Returns the starting index of the ‘occurrence’th occurrence of substring ‘pattern’ in input ‘string’ Returns an integer
- Arguments:
- stringcharacter(len=*), intent(in)
- patterntype(string_type), intent(in)
- occurrenceinteger, intent(in), optional
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
find_char_char (function)#
-
elemental function find_char_char(string, pattern, occurrence, consider_overlapping) -> res Returns the starting index of the ‘occurrence’th occurrence of substring ‘pattern’ in input ‘string’ Returns an integer
- Arguments:
- stringcharacter(len=*), intent(in)
- patterncharacter(len=*), intent(in)
- occurrenceinteger, intent(in), optional
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
replace_all_string_string_string (function)#
-
pure function replace_all_string_string_string(string, pattern, replacement) -> res Replaces all occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- patterntype(string_type), intent(in)
- replacementtype(string_type), intent(in)
- Returns:
- restype(string_type)
replace_all_string_string_char (function)#
-
pure function replace_all_string_string_char(string, pattern, replacement) -> res Replaces all occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- patterntype(string_type), intent(in)
- replacementcharacter(len=*), intent(in)
- Returns:
- restype(string_type)
replace_all_string_char_string (function)#
-
pure function replace_all_string_char_string(string, pattern, replacement) -> res Replaces all occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- patterncharacter(len=*), intent(in)
- replacementtype(string_type), intent(in)
- Returns:
- restype(string_type)
replace_all_char_string_string (function)#
-
pure function replace_all_char_string_string(string, pattern, replacement) -> res Replaces all occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- patterntype(string_type), intent(in)
- replacementtype(string_type), intent(in)
- Returns:
- rescharacter(len=:), allocatable
replace_all_string_char_char (function)#
-
pure function replace_all_string_char_char(string, pattern, replacement) -> res Replaces all occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- patterncharacter(len=*), intent(in)
- replacementcharacter(len=*), intent(in)
- Returns:
- restype(string_type)
replace_all_char_string_char (function)#
-
pure function replace_all_char_string_char(string, pattern, replacement) -> res Replaces all occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- patterntype(string_type), intent(in)
- replacementcharacter(len=*), intent(in)
- Returns:
- rescharacter(len=:), allocatable
replace_all_char_char_string (function)#
-
pure function replace_all_char_char_string(string, pattern, replacement) -> res Replaces all occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- patterncharacter(len=*), intent(in)
- replacementtype(string_type), intent(in)
- Returns:
- rescharacter(len=:), allocatable
replace_all_char_char_char (function)#
-
pure function replace_all_char_char_char(string, pattern, replacement) -> res Replaces all the occurrences of substring ‘pattern’ in the input ‘string’ with the replacement ‘replacement’ Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- patterncharacter(len=*), intent(in)
- replacementcharacter(len=*), intent(in)
- Returns:
- rescharacter(len=:), allocatable
padl_string_default (function)#
-
pure function padl_string_default(string, output_length) -> res Left pad the input string with “ “ (1 whitespace)
Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- output_lengthinteger, intent(in)
- Returns:
- restype(string_type)
padl_string_pad_with (function)#
-
pure function padl_string_pad_with(string, output_length, pad_with) -> res Left pad the input string with the ‘pad_with’ character
Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- output_lengthinteger, intent(in)
- pad_withcharacter(len=1), intent(in)
- Returns:
- restype(string_type)
padl_char_default (function)#
-
pure function padl_char_default(string, output_length) -> res Left pad the input string with “ “ (1 whitespace)
Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- output_lengthinteger, intent(in)
- Returns:
- rescharacter(kind=output_length), len=max)
padl_char_pad_with (function)#
-
pure function padl_char_pad_with(string, output_length, pad_with) -> res Left pad the input string with the ‘pad_with’ character
Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- output_lengthinteger, intent(in)
- pad_withcharacter(len=1), intent(in)
- Returns:
- rescharacter(kind=output_length), len=max)
padr_string_default (function)#
-
pure function padr_string_default(string, output_length) -> res Right pad the input string with “ “ (1 whitespace)
Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- output_lengthinteger, intent(in)
- Returns:
- restype(string_type)
padr_string_pad_with (function)#
-
pure function padr_string_pad_with(string, output_length, pad_with) -> res Right pad the input string with the ‘pad_with’ character
Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- output_lengthinteger, intent(in)
- pad_withcharacter(len=1), intent(in)
- Returns:
- restype(string_type)
padr_char_default (function)#
-
pure function padr_char_default(string, output_length) -> res Right pad the input string with “ “ (1 whitespace)
Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- output_lengthinteger, intent(in)
- Returns:
- rescharacter(kind=output_length), len=max)
padr_char_pad_with (function)#
-
pure function padr_char_pad_with(string, output_length, pad_with) -> res Right pad the input string with the ‘pad_with’ character
Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- output_lengthinteger, intent(in)
- pad_withcharacter(len=1), intent(in)
- Returns:
- rescharacter(kind=output_length), len=max)
count_string_string (function)#
-
elemental function count_string_string(string, pattern, consider_overlapping) -> res Returns the number of times substring ‘pattern’ has appeared in the input string ‘string’ Returns an integer
- Arguments:
- stringtype(string_type), intent(in)
- patterntype(string_type), intent(in)
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
count_string_char (function)#
-
elemental function count_string_char(string, pattern, consider_overlapping) -> res Returns the number of times substring ‘pattern’ has appeared in the input string ‘string’ Returns an integer
- Arguments:
- stringtype(string_type), intent(in)
- patterncharacter(len=*), intent(in)
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
count_char_string (function)#
-
elemental function count_char_string(string, pattern, consider_overlapping) -> res Returns the number of times substring ‘pattern’ has appeared in the input string ‘string’ Returns an integer
- Arguments:
- stringcharacter(len=*), intent(in)
- patterntype(string_type), intent(in)
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
count_char_char (function)#
-
elemental function count_char_char(string, pattern, consider_overlapping) -> res Returns the number of times substring ‘pattern’ has appeared in the input string ‘string’ Returns an integer
- Arguments:
- stringcharacter(len=*), intent(in)
- patterncharacter(len=*), intent(in)
- consider_overlappinglogical, intent(in), optional
- Returns:
- resinteger
zfill_string (function)#
-
pure function zfill_string(string, output_length) -> res Left pad the input string with zeros
Returns a new string
- Arguments:
- stringtype(string_type), intent(in)
- output_lengthinteger, intent(in)
- Returns:
- restype(string_type)
zfill_char (function)#
-
pure function zfill_char(string, output_length) -> res Left pad the input string with zeros
Returns a new string
- Arguments:
- stringcharacter(len=*), intent(in)
- output_lengthinteger, intent(in)
- Returns:
- rescharacter(kind=output_length), len=max)
to_c_char_from_char (function)#
-
pure function to_c_char_from_char(value) -> cstr Convert a Fortran character string to a C character array
Version: experimental
- Arguments:
- valuecharacter(len=*), intent(in)
- Returns:
- cstrcharacter(kind=c_char, len=1), dimension(len(value)+1)
to_c_char_from_string (function)#
-
pure function to_c_char_from_string(value) -> cstr Convert a Fortran string type to a C character array
Version: experimental
- Arguments:
- valuetype(string_type), intent(in)
- Returns:
- cstrcharacter(kind=c_char, len=1), dimension(len(value)+1)
join_string (function)#
-
pure function join_string(strings, separator) -> join_string Joins a list of strings with a separator (default: space). Returns a new string
- Arguments:
- stringstype(string_type), intent(in), dimension(:)
- separatorcharacter(len=*), intent(in), optional
- Returns:
- join_stringtype(string_type)
join_char (function)#
-
pure function join_char(strings, separator) -> joined Joins a list of strings with a separator (default: space). Returns a new string
- Arguments:
- stringscharacter(len=*), intent(in), dimension(:)
- separatorcharacter(len=*), intent(in), optional
- Returns:
- joinedcharacter(len=:), allocatable