[UP]


Manual Reference Pages  - substitute (3)

NAME

substitute(3f) - [M_strings:EDITING] subroutine globally substitutes one substring for another in string (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Examples
Author
License

SYNOPSIS

subroutine substitute(targetline,old,new,ierr,start,end)

    character(len=*)              :: targetline
    character(len=*),intent(in)   :: old
    character(len=*),intent(in)   :: new
    integer,intent(out),optional  :: ierr
    integer,intent(in),optional   :: start
    integer,intent(in),optional   :: end

DESCRIPTION

Globally substitute one substring for another in string.

OPTIONS

TARGETLINE
  input line to be changed. Must be long enough to hold altered output.
OLD substring to find and replace
NEW replacement for OLD substring
IERR error code. If IER = -1 bad directive, >= 0 then count of changes made.
START sets the left margin to be scanned for OLD in TARGETLINE.
END sets the right margin to be scanned for OLD in TARGETLINE.

EXAMPLES

Sample Program:

   program demo_substitute
   use M_strings, only : substitute
   implicit none
   ! must be long enough to hold changed line
   character(len=80) :: targetline

targetline=’this is the input string’ write(*,*)’ORIGINAL : ’//trim(targetline)

! changes the input to ’THis is THe input string’ call substitute(targetline,’th’,’TH’) write(*,*)’th => TH : ’//trim(targetline)

! a null old substring means "at beginning of line" ! changes the input to ’BEFORE:this is the input string’ call substitute(targetline,’’,’BEFORE:’) write(*,*)’"" => BEFORE: ’//trim(targetline)

! a null new string deletes occurrences of the old substring ! changes the input to ’ths s the nput strng’ call substitute(targetline,’i’,’’) write(*,*)’i => "" : ’//trim(targetline)

end program demo_substitute

Expected output

    ORIGINAL    : this is the input string
    th => TH    : THis is THe input string
    "" => BEFORE: BEFORE:THis is THe input string
    i => ""     : BEFORE:THs s THe nput strng

AUTHOR

John S. Urban

LICENSE

Public Domain


substitute (3) March 11, 2021
Generated by manServer 1.08 from e27f068d-6eac-4db4-a00e-7fbc554f884e using man macros.