[UP]


Manual Reference Pages  - stretch (3)

NAME

stretch(3f) - [M_strings:LENGTH] return string padded to at least specified length (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

SYNOPSIS

function stretch(str,length,pattern,suffix) result(strout)

character(len=*),intent(in) :: str integer,intent(in) :: length character(len=*)intent(in),optional :: pattern character(len=*)intent(in),optional :: suffix character(len=:),allocatable :: strout

DESCRIPTION

stretch(3f) pads a string with spaces to at least the specified length. If the trimmed input string is longer than the requested length the original string is returned trimmed of trailing spaces.

OPTIONS

str the input string to return trimmed, but then padded to the specified length if shorter than length
length The minimum string length to return
pattern
  optional string to use as padding. Defaults to a space.
suffix optional string to append to output string

RETURNS

strout The input string padded to the requested length or the trimmed input string if the input string is longer than the requested length.

EXAMPLE

Sample Program:

    program demo_stretch
     use M_strings, only : stretch
     implicit none
     character(len=10)            :: string=’abcdefghij’
     character(len=:),allocatable :: answer
     integer                      :: i
        answer=stretch(string,5)
        write(*,’("[",a,"]")’) answer
        answer=stretch(string,20)
        write(*,’("[",a,"]")’) answer
        i=30
        write(*,*)
        write(*,’(1x,a,i0)’) stretch(’CHAPTER 1 : The beginning ’,i,’.’), 1
        write(*,’(1x,a,i0)’) stretch(’CHAPTER 2 : The end ’,i,’.’),       1234
        write(*,’(1x,a,i0)’) stretch(’APPENDIX ’,i,’.’),                  1235
        write(*,*)
        write(*,’(1x,a,i7)’) stretch(’CHAPTER 1 : The beginning ’,i,’.’), 1
        write(*,’(1x,a,i7)’) stretch(’CHAPTER 2 : The end ’,i,’.’),       1234
        write(*,’(1x,a,i7)’) stretch(’APPENDIX ’,i,’.’),                  1235
        write(*,*)
        write(*,*) stretch(’CHAPTER 1 : The beginning ’,i,suffix=’: ’), 1
        write(*,*) stretch(’CHAPTER 2 : The end ’,i,suffix=’: ’),       1234
        write(*,*) stretch(’APPENDIX ’,i,suffix=’: ’),                  1235
    end program demo_stretch

Results:

   [abcdefghij]
   [abcdefghij          ]

CHAPTER 1 : The beginning ....1 CHAPTER 2 : The end ..........1234 APPENDIX .....................1235

CHAPTER 1 : The beginning .... 1 CHAPTER 2 : The end .......... 1234 APPENDIX ..................... 1235

CHAPTER 1 : The beginning : 1 CHAPTER 2 : The end : 1234 APPENDIX : 1235

AUTHOR

John S. Urban

LICENSE

Public Domain


stretch (3) July 05, 2020
Generated by manServer 1.08 from 27db35f3-7908-4711-a6ea-de2cc4cd6f75 using man macros.