ad_pad (public)
ad_pad [ -left ] [ -right ] string length padstring
Defined in packages/acs-tcl/tcl/text-html-procs.tcl
Tcl implementation of the pad string function found in many DBMSs. One of the directional flags -left or -right must be specified and will dictate whether this will be a lpad or a rpad.
- Switches:
- -left (optional, boolean)
- text will be appended left of the original string.
- -right (optional, boolean)
- text will be appended right of the original string.
- Parameters:
- string (required)
- length (required)
- padstring (required)
- Returns:
- padded string
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- ad_pad
Source code: if {!($left_p ^ $right_p)} { error "Please specify single flag -left or -right" } if {$length < 1 || ![string is integer -strict $length]} { error "length ($length) must be an integer > 0" } set slength [string length $string] set padlength [string length $padstring] set repetitions [expr {int(($length - $slength) / $padlength) + 1}] set appended [string repeat $padstring $repetitions] incr length -1 if {$left_p} { set string [string range $appended$string end-$length end] } else { set string [string range $string$appended 0 $length] } return $stringXQL Not present: Generic, PostgreSQL, Oracle