replace Function

public pure function replace(str_in, find, rep) result(str_out)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str_in
character(len=*), intent(in) :: find
character(len=*), intent(in) :: rep

Return Value character(len=LEN)


Called by

proc~~replace~~CalledByGraph proc~replace replace proc~fillstrings FillStrings proc~fillstrings->proc~replace proc~findstr FindStr proc~findstr->proc~replace

Source Code

PURE FUNCTION replace(str_in,find,rep) RESULT(str_out)
  IMPLICIT NONE
  !-------------------------------------------
  ! input
  CHARACTER(LEN=*),INTENT(IN) :: str_in
  CHARACTER(LEN=*),INTENT(IN) :: find
  CHARACTER(LEN=*),INTENT(IN) :: rep
  ! output
  CHARACTER(LEN=LEN(str_in)) :: str_out
  !-------------------------------------------
  ! LOCAL VARIABLES
  CHARACTER(LEN=LEN(str_in)) :: str_tmp
  INTEGER :: i_find,lfind,lrep
  !=============================================================================
  str_out=""
  str_tmp=TRIM(str_in)
  i_find=INDEX(str_tmp,TRIM(find))
  lfind=LEN_TRIM(find)
  lrep=LEN_TRIM(rep)
  DO WHILE (i_find > 0)
    str_out=TRIM(str_out)//str_tmp(1:i_find-1)//TRIM(rep)
    str_tmp=str_tmp(i_find+lfind:)
    i_find=INDEX(str_tmp,TRIM(find))
  END DO
  str_out=TRIM(str_out)//TRIM(str_tmp)
END FUNCTION replace