June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
76
Task/String-case/Fortran/string-case-4.f
Normal file
76
Task/String-case/Fortran/string-case-4.f
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
module uplow
|
||||
implicit none
|
||||
character(len=26), parameter, private :: low = "abcdefghijklmnopqrstuvwxyz"
|
||||
character(len=26), parameter, private :: high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
contains
|
||||
|
||||
function to_upper(s) result(t)
|
||||
! returns upper case of s
|
||||
implicit none
|
||||
character(len=*), intent(in) :: s
|
||||
character(len=len(s)) :: t
|
||||
|
||||
character(len=1), save :: convtable(0:255)
|
||||
logical, save :: first = .true.
|
||||
integer :: i
|
||||
|
||||
if(first) then
|
||||
do i=0,255
|
||||
convtable(i) = char(i)
|
||||
enddo
|
||||
do i=1,len(low)
|
||||
convtable(iachar(low(i:i))) = char(iachar(high(i:i)))
|
||||
enddo
|
||||
first = .false.
|
||||
endif
|
||||
|
||||
t = s
|
||||
|
||||
do i=1,len_trim(s)
|
||||
t(i:i) = convtable(iachar(s(i:i)))
|
||||
enddo
|
||||
|
||||
end function to_upper
|
||||
|
||||
function to_lower(s) result(t)
|
||||
! returns lower case of s
|
||||
implicit none
|
||||
character(len=*), intent(in) :: s
|
||||
character(len=len(s)) :: t
|
||||
|
||||
character(len=1), save :: convtable(0:255)
|
||||
logical, save :: first = .true.
|
||||
integer :: i
|
||||
|
||||
if(first) then
|
||||
do i=0,255
|
||||
convtable(i) = char(i)
|
||||
enddo
|
||||
do i = 1,len(low)
|
||||
convtable(iachar(high(i:i))) = char(iachar(low(i:i)))
|
||||
enddo
|
||||
first = .false.
|
||||
endif
|
||||
|
||||
t = s
|
||||
|
||||
do i=1,len_trim(s)
|
||||
t(i:i) = convtable(iachar(s(i:i)))
|
||||
enddo
|
||||
|
||||
end function to_lower
|
||||
|
||||
|
||||
end module uplow
|
||||
|
||||
|
||||
program doit
|
||||
use uplow
|
||||
character(len=40) :: s
|
||||
|
||||
s = "abcdxyz ZXYDCBA _!@"
|
||||
print *,"original: ",'[',s,']'
|
||||
print *,"to_upper: ",'[',to_upper(s),']'
|
||||
print *,"to_lower: ",'[',to_lower(s),']'
|
||||
|
||||
end program doit
|
||||
Loading…
Add table
Add a link
Reference in a new issue