Manual Reference Pages  - len_trim (3m_unicode)

NAME

LEN_TRIM(3f) - [M_unicode:WHITESPACE] string length without trailing blank characters (LICENSE:MIT)

CONTENTS

Synopsis
Characteristics
Description
Options
Result
Examples
See Also
Author
License

SYNOPSIS

result = len_trim(string)

         elemental integer(kind=kind) function len_trim(string)

character(len=*),intent(in) :: string

CHARACTERISTICS

o string is of type type(unicode_type)
o the return value is of type default integer.

DESCRIPTION

len_trim(3) returns the length of a string, ignoring any trailing blanks.

OPTIONS

o string : the input string whose length is to be measured.

RESULT

the result equals the number of glyphs remaining after any trailing blanks in string are removed.

if the input argument is of zero length or all blanks the result is zero.

EXAMPLES

sample program

   program demo_len_trim
   use M_unicode, only : ut=>unicode_type, assignment(=)
   use M_unicode, only : len,len_trim
   use M_unicode, only : write(formatted)
   implicit none
   type(ut) :: string
   integer  :: i
   ! basic usage
      string=" how long is this string?     "
      print ’(DT)’,  string
      print *, ’untrimmed length=’,len(string)
      print *, ’trimmed length=’,len_trim(string)
      !
      ! print string, then print substring of string
      string=’xxxxx   ’
      write(*,’(*(DT))’)string,string,string
      i=len_trim(string)
      print ’(*(DT))’,string%sub(1,i),string%sub(1,i),string%sub(1,i)
      !
      ! elemental example
      ele:block
      ! an array of strings may be used
      type(ut),allocatable :: tablet(:)
      tablet=[ &
      & ut(’ how long is this string?     ’),&
      & ut(’and this one?’)]
         write(*,*)’untrimmed length=  ’,len(tablet)
         write(*,*)’trimmed length=    ’,len_trim(tablet)
         write(*,*)’sum trimmed length=’,sum(len_trim(tablet))
      endblock ele
      !
   end program demo_len_trim

results:

   >  how long is this string?
   >  untrimmed length=          30
   >  trimmed length=          25
   > xxxxx   xxxxx   xxxxx
   > xxxxxxxxxxxxxxx
   >  untrimmed length=            30          13
   >  trimmed length=              25          13
   >  sum trimmed length=          38

SEE ALSO

functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
o elemental: adjustl(3), adjustr(3), index(3), scan(3), verify(3)
o nonelemental: repeat(3), len(3), trim(3)

AUTHOR

John S. Urban

LICENSE

    MIT