stretch(3f) - [M_strings:LENGTH] return string padded to at least specified length (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
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
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.
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
strout The input string padded to the requested length or the trimmed input string if the input string is longer than the requested length.
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 ,& & stretch(CHAPTER 2 : The end ,i,.), 1234 ,& & stretch(APPENDIX ,i,.), 1235 write(*,*) write(*,(1x,a,i7)) & & stretch(CHAPTER 1 : The beginning ,i,.), 1 ,& & stretch(CHAPTER 2 : The end ,i,.), 1234 ,& & 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_stretchResults:
[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
John S. Urban
Public Domain
Nemo Release 3.1 | stretch (3m_strings) | January 10, 2025 |