[Fortran] 纯文本查看 复制代码 program main
character(80),allocatable:: word(:)
character(80) substring, spliter
integer i, id,len_spliter,len_substring
integer,parameter ::ncol=4
allocate(word(ncol))
open(unit=12,file='a.txt')
read(12,'(A)') substring
write(*,*)'分隔符:'
read(*,*)spliter
len_spliter=len(trim(spliter))
substring = adjustl(substring)
len_substring=len(trim(substring))
do i=1,ncol-1
id=index(substring,trim(spliter))
word(i)=substring(1:(id-1))
write(*,*) trim(word(i))
substring=substring((id+len_spliter):)
end do
word(ncol)=substring
write(*,*) trim(word(ncol))
pause
end
|