[UP]


Manual Reference Pages  - chomp (3)

NAME

chomp(3f) - [M_strings:TOKENS] Tokenize a string, consuming it one token per call (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

function chomp(source_string,token[,delimiters])

character(len=*) :: source_string character(len=:),intent(out),token :: token character(len=:),intent(in),optional :: delimiters integer :: chomp

DESCRIPTION

The CHOMP(3f) function is used to isolate sequential tokens in a string, SOURCE_STRING. These tokens are delimited in the string by at least one of the characters in DELIMITERS. This routine consumes the source_string one token per call. It returns -1 when complete. The default delimiter list is "space,tab,carriage return,newline".

OPTIONS

SOURCE_STRING
  string to tokenize
DELIMITERS
  list of separator characters

RETURNS

TOKEN returned token
CHOMP status flag. 0 = success, -1 = no tokens remain

EXAMPLES

Sample program:

   program demo_chomp

use M_strings, only : chomp implicit none character(len=100) :: inline character(len=:),allocatable :: token character(len=*),parameter :: delimiters=’ ;,’ integer :: ios integer :: icount integer :: itoken icount=0 do ! read lines from stdin until end-of-file or error read (unit=*,fmt="(a)",iostat=ios) inline if(ios.ne.0)stop icount=icount+1 itoken=0 write(*,*)’INLINE ’,trim(inline) do while ( chomp(inline,token,delimiters).ge. 0) itoken=itoken+1 print *, itoken,’TOKEN=[’//trim(token)//’]’ enddo enddo

end program demo_chomp

sample input file

    this is a test of chomp; A:B :;,C;;

sample output file

    INLINE     this is a test of chomp; A:B :;,C;;
              1 TOKEN=[this]
              2 TOKEN=[is]
              3 TOKEN=[a]
              4 TOKEN=[test]
              5 TOKEN=[of]
              6 TOKEN=[chomp]
              7 TOKEN=[A:B]
              8 TOKEN=[:]
              9 TOKEN=[C]

AUTHOR

John S. Urban

LICENSE

Public Domain


chomp (3) July 05, 2020
Generated by manServer 1.08 from f923651a-b961-480c-9cf5-38f4e9a26aae using man macros.