Logo

Programming-Idioms

History of Idiom 49 > diff from v39 to v40

Edit summary for version 40 by none:
New Fortran implementation by user [none]

Version 39

2019-09-28, 17:12:53

Version 40

2019-09-29, 22:12:38

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Illustration

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Illustration
Code
program main
use stringifor_string_t ! https://github.com/szaghi/StringiFor
   implicit none
   type( string ) ::  string1
   type( string ), allocatable :: substrings( : )
   integer :: i

   string1 =  " Build list _chunks consisting in substrings of input string _s  separated by one or more space characters"
   call string1%split(sep=' ', tokens=substrings )
   do i=1,size(substrings, dim=1)
   write(*,*) substrings(i)
   enddo
end program main