scripting@wanadoo.nl




PadStr()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
15 June 2002 PadStr()
AuthorHoward A. Bullock
Action Left pad or Right pad a string with specified character(s) to a specified overall length.
SyntaxPadStr ($input, $pad, $length, $padside) 
Parameters
  • $input (Required / String) String value to which padding is added.
  • $pad (Required / String) One or more characters to be added to the Left or Right of the string $Input.
  • $length (Required / Numeric) The length to which $Input with padding will be trimmed before it is returned through the function.
  • $padside (Optional / String) String [L|R] Default is "L" 
  • RemarksThe "$pad" can be one or more characters. If the Padding exceeds the specified maximum length then the resulting string is trimmed preserving the original data. 
    ReturnsString 
    DependenciesNone. 
    Examples
    PadStr("401","0",8)           result "00000401"
    PadStr("401","0",8,"R")       result "40100000"
    
     
    Source
    FUNCTION PadStr ($input, $pad, $length, OPTIONAL $padside)
      DIM $i, $x
      $padstr = ""
      $input = "" + $input
      $pad = "" + $pad
      $length = Int($length)
      IF ($padside = "") OR (Len($padside) > 1) OR (InStr("LR",$padside) = 0)
        $padside = "L"
      ENDIF
      $x = Len($input)
      FOR $i = $x TO $length - 1 STEP Len($pad)
        IF ($padside = "L")
          $input = $pad + $input
        ELSE
          $input = $input + $pad
        ENDIF
      NEXT
      IF ($padside = "L")
        $input = Right($input, $length)
      ELSE
        $input = Left($input, $length)
      ENDIF
      $padstr = $input
      EXIT 0
    ENDFUNCTION ; - PadStr -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter