Character handling in Fortran
Fixed-length strings, and the trims and finds that make them behave.
program character_ops
implicit none
character(len=20) :: port = "Valparaiso"
character(len=40) :: tag
! // concatenates; trim drops the padding a fixed length carries.
tag = trim(port) // ", berth 9"
print *, tag
print *, "name length: ", len_trim(port)
print *, "finds 'para': ", index(port, "para")
print *, "right-shifted: [", adjustr(port), "]"
end program character_ops
How it works
character(len=20)pads with trailing blanks;trimdrops them for splicing.//concatenates the trimmed port name onto its berth.len_trim,index, andadjustrmeasure, search, and shift the text.
Keywords and builtins used here
adjustrcharacterendimplicitindexlenlen_trimnoneprintprogramtrim
The run, in numbers
- Lines
- 12
- Characters to type
- 376
- Tokens
- 70
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 65 seconds.
Step 1 of 3 in Strings & formats, step 16 of 27 in Language basics.