-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo_replace.f90
executable file
·35 lines (25 loc) · 1.3 KB
/
demo_replace.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
program demo_replace
use M_strings, only : replace
implicit none
character(len=:),allocatable :: line
write(*,*)replace('Xis is Xe string','X','th')
write(*,*)replace('Xis is xe string','x','th',ignorecase=.true.)
write(*,*)replace('Xis is xe string','X','th',ignorecase=.false.)
! a null old substring means "at beginning of line"
write(*,*) replace('my line of text','','BEFORE:')
! a null new string deletes occurrences of the old substring
write(*,*) replace('I wonder i ii iii','i','')
! Examples of the use of RANGE
line=replace('aaaaaaaaa','a','A',occurrence=1,repeat=1)
write(*,*)'replace first a with A ['//line//']'
line=replace('aaaaaaaaa','a','A',occurrence=3,repeat=3)
write(*,*)'replace a with A for 3rd to 5th occurrence ['//line//']'
line=replace('ababababa','a','',occurrence=3,repeat=3)
write(*,*)'replace a with null instances 3 to 5 ['//line//']'
line=replace( &
& 'a b ab baaa aaaa aa aa a a a aa aaaaaa',&
& 'aa','CCCC',occurrence=-1,repeat=1)
write(*,*)'replace lastaa with CCCC ['//line//']'
write(*,*)replace('myf90stuff.f90.f90','f90','for',occurrence=-1,repeat=1)
write(*,*)replace('myf90stuff.f90.f90','f90','for',occurrence=-2,repeat=2)
end program demo_replace