replace Function

public pure function replace(string, charset, target_char) result(res)

Returns string with characters in charset replaced with target_char.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
character(len=1), intent(in) :: charset(:)
character(len=1), intent(in) :: target_char

Return Value character(len=len(string))


Source Code

pure function replace(string, charset, target_char) result(res)
    character(*), intent(in) :: string
    character, intent(in) :: charset(:), target_char
    character(len(string)) :: res
    integer :: n
    res = string
    do n = 1, len(string)
        if (any(string(n:n) == charset)) then
            res(n:n) = target_char
        end if
    end do
end function replace