Fortran程序设计之子程序.pdf
文本预览下载声明
第5章 字符数据
字符串的声明
• 定长度的字符串
• character(len=7) string_7
• 动态字符串
• character(len=:), allocatable line_4
• 字符串数组
• character(len=20), dimension(5, 9, 7) string_array
• 空字符
• ,
2
字符串的声明
• 定长度的字符串
• character(len=7) string_7
• 动态字符串 Fortran 2003以后才支持动态字符串
• character(len=:), allocatable line_4
• 字符串数组
• character(len=20), dimension(5, 9, 7) string_array
• 空字符
• ,
2
program test_character
implicit none
character(len=:),allocatable line_4
line_4=
print*,line_4,len(line_4),sizeof(line_4)
line_4=test
print*,line_4,len(line_4),sizeof(line_4)
line_4=testtest
print*,line_4,len(line_4),sizeof(line_4)
end program
3
字符常量
• 符号常量
program hello
implicit none
character(len=*), parameter
message = Hello, I am a computer.
print *, message
end program
• 直接常量
• 用单引号或双引号(有的地方又称单撇号、
双撇号)括起来的字符串
4
字符常量
• 符号常量
program hello
implicit none
character(len=*), parameter
message = Hello, I am a computer.
print *, message
end program
• 直接常量
• 用单引号或双引号(有的地方又称单撇号、
双撇号)括起来的字符串
4
字符串中含有单引号或双引号的处理
• 当字符串中又含有单撇号时例如要将IM A
STUDENT作为一个字符串来处理,为了区分是
字符串中的字符还是定界符,可采用两种方式表
示:
• IM A STUDENT
• IM A STUDENT
• 前者用双撇号作定界符,后者用单撇号作定界符,
而将字符串的单撇号用两个单撇号表示,系统会
自动将其处理为字符串的一个单撇号字符。
5
字符串中含有单引号或双
显示全部