Description
The functx:pad-string-to-length function returns $stringToPad appended with enough repetitions of $padChar to make its length $length . The function will truncate $stringToPad if its length is greater than $length .
Arguments and Return TypeName | Type | Description |
$stringToPad |
xs:string? |
the string to pad |
$padChar |
xs:string |
the character(s) to use as padding |
$length |
xs:integer |
the desired length |
return value |
xs:string |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:pad-string-to-length
( $stringToPad as xs:string? ,
$padChar as xs:string ,
$length as xs:integer ) as xs:string {
substring(
string-join (
($stringToPad, for $i in (1 to $length) return $padChar)
,'')
,1,$length)
} ; |
ExamplesXQuery Example | Results |
---|
functx:pad-string-to-length('abc', '*', 6) |
abc*** |
functx:pad-string-to-length('abcdef', '*', 4) |
abcd |
functx:pad-string-to-length('', '*', 4) |
**** |
See AlsoHistory |
Recommended Reading:
|