C Library Functions  - lpad (3)

NAME

lpad(3f) - [M_strings:LENGTH] convert to a cropped string and then blank-pad on the left to requested length (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

SYNOPSIS

function lpad(valuein,length) result(strout)

    class*,intent(in)       :: valuein(..)
    integer,intent(in)      :: length

DESCRIPTION

lpad(3f) converts a scalar value to a cropped string and then pads it on the left with spaces to at least the specified length. If the trimmed input is longer than the requested length the string is returned trimmed of leading and trailing spaces.

OPTIONS

str The input may be scalar or a vector. the input value to return as a string, padded on the left to the specified length if shorter than length. The input may be any intrinsic scalar which is converted to a cropped string much as if written with list-directed output.
length The minimum string length to return

RETURNS

strout The input string padded to the requested length on the left with spaces.

EXAMPLE

Sample Program:

     program demo_lpad
      use M_strings, only : lpad
      implicit none
         write(*,’("[",a,"]")’) lpad( ’my string’, 20)
         write(*,’("[",a,"]")’) lpad( ’my string   ’, 20)
         write(*,’("[",a,"]")’) lpad( ’   my string’, 20)
         write(*,’("[",a,"]")’) lpad( ’   my string   ’, 20)
         write(*,’("[",a,"]")’) lpad( valuein=42 , length=7)
         write(*,’("[",a,"]")’) lpad( valuein=1.0/9.0 , length=20)
     end program demo_lpad

Results:

    > [           my string]
    > [           my string]
    > [           my string]
    > [           my string]
    > [     42]
    > [         0.111111112]

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 lpad (3) July 22, 2023
Generated by manServer 1.08 from 7e138547-ab8e-4560-b37d-c3d518da2f96 using man macros.