Replace substring (all occurrences) into a string.
Note
Leading and trailing white spaces are stripped out.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | string |
String to be modified. |
||
character(len=*), | intent(in) | :: | substring |
Substring to be replaced. |
||
character(len=*), | intent(in) | :: | restring |
String to be inserted. |
New modified string.
pure function replace_all(string, substring, restring) result(newstring) !< Replace substring (all occurrences) into a string. !< !< @note Leading and trailing white spaces are stripped out. character(len=*), intent(in) :: string !< String to be modified. character(len=*), intent(in) :: substring !< Substring to be replaced. character(len=*), intent(in) :: restring !< String to be inserted. character(len=:), allocatable :: newstring !< New modified string. newstring = wstrip(string) do if (index(newstring, substring)>0) then newstring = replace(string=newstring, substring=substring, restring=restring) else exit endif enddo endfunction replace_all