Return the position of the start of the first occurrence of string substring as a substring in string, counting from one.
If substring is not present in string, zero is returned. If the back argument is present and true, the return value is
the start of the last occurrence rather than the first.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(string), | intent(in) | :: | self | The string. |
||
| character(kind=CK,len=*), | intent(in) | :: | substring | Searched substring. |
||
| logical, | intent(in), | optional | :: | back | Start of the last occurrence rather than the first. |
Result of the search.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
elemental function sindex_string_character(self, substring, back) result(i)
!---------------------------------------------------------------------------------------------------------------------------------
!< Return the position of the start of the first occurrence of string `substring` as a substring in `string`, counting from one.
!< If `substring` is not present in `string`, zero is returned. If the back argument is present and true, the return value is
!< the start of the last occurrence rather than the first.
!---------------------------------------------------------------------------------------------------------------------------------
class(string), intent(in) :: self !< The string.
character(kind=CK, len=*), intent(in) :: substring !< Searched substring.
logical, intent(in), optional :: back !< Start of the last occurrence rather than the first.
integer :: i !< Result of the search.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (allocated(self%raw)) then
i = index(string=self%raw, substring=substring, back=back)
else
i = 0
endif
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction sindex_string_character