SPLIT
— Parse a string into tokens, one at a time ¶RESULT = SPLIT(STRING, SET, POS [, BACK])
Updates the integer POS to the position of the next (or previous) separator in STRING.
If BACK is absent or is present with the value false, POS is assigned the position of the leftmost token delimiter in STRING whose position is greater than POS, or if there is no such character, it is assigned a value one greater than the length of STRING. This identifies a token with starting position one greater than the value of POS on invocation, and ending position one less than the value of POS on return.
If BACK is present with the value true, POS is assigned the position of the rightmost token delimiter in STRING whose position is less than POS, or if there is no such character, it is assigned the value zero. This identifies a token with ending position one less than the value of POS on invocation, and starting position one greater than the value of POS on return.
Subroutine
STRING | Shall be of type CHARACTER . |
SET | Shall be of type CHARACTER . |
POS | Shall be of type INTEGER . |
BACK | (Optional) Shall be of type LOGICAL . |
character(len=:), allocatable :: input character(len=2) :: set = ', ' integer :: p input = "one,last example" p = 0 do if (p > len(input)) exit istart = p + 1 call split(input, set, p) iend = p - 1 print '(t7, a)', input(istart:iend) end do
Fortran 2023
SCAN
— Scan a string for the presence of a set of characters