sep(3f) - [M_strings:TOKENS] function to parse string into an array using specified delimiters (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
function sep(input_line,delimiters,nulls)
character(len=*),intent(in) :: input_line character(len=*),optional,intent(in) :: delimiters character(len=*),optional,intent(in) :: nulls character(len=:),allocatable :: sep(:)
sep(3f) parses a string using specified delimiter characters and store tokens into an allocatable array
INPUT_LINE Input string to tokenize DELIMITERS List of delimiter characters. The default delimiters are the "whitespace" characters (space, tab,new line, vertical tab, formfeed, carriage return, and null). You may specify an alternate set of delimiter characters. Multi-character delimiters are not supported (Each character in the DELIMITERS list is considered to be a delimiter).
Quoting of delimiter characters is not supported.
NULLS=IGNORE|RETURN|IGNOREEND Treatment of null fields. By default adjacent delimiters in the input string do not create an empty string in the output array. if NULLS=return adjacent delimiters create an empty element in the output ARRAY. If NULLS=ignoreend then only trailing delimiters at the right of the string are ignored. ORDER=ASCENDING|DESCENDING by default the tokens are returned from last to first; order=ASCENDING returns them from first to last (left to right).
SEP Output array of tokens
Sample program:
program demo_sep use M_strings, only: sep character(len=*),parameter :: fo=(/,a,*(/,"[",g0,"]":,",")) character(len=*),parameter :: line=& aBcdef ghijklmnop qrstuvwxyz 1:|:2 333|333 a B cc write(*,(a)) INPUT LINE:[//LINE//] write(*,fo) typical call:,sep(line) write(*,fo) delimiters ":|":,sep(line,:|) write(*,fo) count null fields ":|":,sep(line,:|,return) end program demo_sepOutput
INPUT LINE:[ aBcdef ghijklmnop qrstuvwxyz 1:|:2 333|333 a B cc ]typical call: [cc ], [B ], [a ], [333|333 ], [1:|:2 ], [qrstuvwxyz], [ghijklmnop], [aBcdef ]
delimiters ":|": [333 a B cc ], [2 333 ], [ aBcdef ghijklmnop qrstuvwxyz 1]
count null fields ":|": [333 a B cc ], [2 333 ], [ ], [ ], [ aBcdef ghijklmnop qrstuvwxyz 1]
John S. Urban
Public Domain
Nemo Release 3.1 | sep (3m_strings) | January 10, 2025 |