-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo_switch.f90
executable file
·48 lines (42 loc) · 1.68 KB
/
demo_switch.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
36
37
38
39
40
41
42
43
44
45
46
47
48
program demo_switch
use M_strings, only : switch, isalpha, islower, nospace
character(len=*),parameter :: &
& dashes='-----------------------------------'
character(len=*),parameter :: string='This is a string'
character(len=1024) :: line
! First, examples of standard Fortran features
! returns array [F,T,T,T,T,T]
write(*,*)['A','=','=','=','=','='] == '='
! this would return T
write(*,*)all(['=','=','=','=','=','='] == '=')
! this would return F
write(*,*)all(['A','=','=','=','=','='] == '=')
! so to test if the string DASHES is all dashes
! using SWITCH(3f) is
if(all(switch(dashes) == '-'))then
write(*,*)'DASHES is all dashes'
endif
! so to test is a string is all letters
! isalpha(3f) returns .true. only if character is a letter
! false because dashes are not a letter
write(*,*) all(isalpha(switch(dashes)))
! false because of spaces
write(*,*) all(isalpha(switch(string)))
! true because removed whitespace
write(*,*) all(isalpha(switch(nospace(string))))
! to see if a string is all uppercase
! show the string
write(*,*) string
! converted to character array
write(*,'(1x,*("[",a,"]":))') switch(string)
write(*,'(*(l3))') islower(switch(string))
! we need a string that is all letters
line=nospace(string)
write(*,*)'LINE=',trim(line)
! all true except first character
write(*,*) islower(switch(nospace(string)))
! should be false
write(*,*) all(islower(switch(nospace(string))))
! should be true
write(*,*) all(islower(switch(nospace(string(2:)))))
end program demo_switch