MONC
Functions/Subroutines
string_utils_mod Module Reference

String utility functionality that is commonly used throughout MONC. More...

Functions/Subroutines

subroutine, public replace_character (str, src_char, tgt_char)
 Replaces all occurances of a character in a string with another character. More...
 

Detailed Description

String utility functionality that is commonly used throughout MONC.

Function/Subroutine Documentation

◆ replace_character()

subroutine, public string_utils_mod::replace_character ( character(len=*), intent(inout)  str,
character, intent(in)  src_char,
character, intent(in)  tgt_char 
)

Replaces all occurances of a character in a string with another character.

Parameters
strThe string to replace characters in (this is modified)
src_charThe source character to look for, which will be replaced
tgt_charWhat to replace source characters with

Definition at line 16 of file string_utils.F90.

17  character(len=*), intent(inout) :: str
18  character, intent(in) :: src_char, tgt_char
19 
20  integer :: i, n, idx
21 
22  n=len_trim(str)
23  i=1
24  do while (i .le. n)
25  idx=index(str(i:n), src_char)
26  if (idx == 0) exit
27  i=i+idx+1
28  str(i-2:i-2)=tgt_char
29  end do
Here is the caller graph for this function: