atleast(3f) - [M_strings:LENGTH] return string padded to at least specified length (LICENSE:PD)
Synopsis
Description
Options
Returns
Example
Author
License
function atleast(str,length,pattern) result(strout)
character(len=*) :: str integer,intent(in) :: length character(len=max(length,len(trim(line)))) :: strout character(len=*),optional :: pattern
atleast(3f) pads a string with spaces to at least the specified length. If the trimmed input string is longer than the requested length the trimmed string is returned.
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.
strout The input string padded to the requested length or the trimmed input string if the input string is longer than the requested length.
Results:Sample Program:
program demo_atleast use M_strings, only : atleast implicit none character(len=10) :: string=abcdefghij character(len=:),allocatable :: answer integer :: i answer=atleast(string,5) write(*,("[",a,"]")) answer answer=atleast(string,20) write(*,("[",a,"]")) answer i=30 write(*,*) write(*,(1x,a,i0)) atleast(CHAPTER 1 : The beginning ,i,.), 1 write(*,(1x,a,i0)) atleast(CHAPTER 2 : The end ,i,.), 1234 write(*,(1x,a,i0)) atleast(APPENDIX ,i,.), 1235 write(*,*) write(*,(1x,a,i7)) atleast(CHAPTER 1 : The beginning ,i,.), 1 write(*,(1x,a,i7)) atleast(CHAPTER 2 : The end ,i,.), 1234 write(*,(1x,a,i7)) atleast(APPENDIX ,i,.), 1235 end program demo_atleast
[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
John S. Urban
Public Domain
atleast (3) | July 05, 2020 |