PadStringToLen(string, char, count)
Last updated June 18, 2002
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
Pads a string to a length of n characters. Padding is from the left. If the length of the string is greater than or equal to the number of characters to pad the string out to, the string is returned unchanged.
Return Values:
Returns a string.
Example:
<CFSET y="test">
<CFOUTPUT>
#PadStringToLen(x, 0, 8)#<BR>
#PadStringToLen(y, "a", 8)#<BR>
#PadStringToLen(y, "a", 2)#
</CFOUTPUT>
Parameters:
| Name | Description | Required |
|---|---|---|
| string | String you want to pad. | Yes |
| char | Character to use as the padding. | Yes |
| count | Total number of characters to pad the string out to. | Yes |
Full UDF Source:
<cfscript>
/**
* Pads a string to a length of n characters. Padding is from the left.
* Based on the UDF PadString() by Rob Brooks-Bilson (rbils@amkor.com).
*
* @param string String you want to pad. (Required)
* @param char Character to use as the padding. (Required)
* @param count Total number of characters to pad the string out to. (Required)
* @return Returns a string.
* @author Stephen Rittler (rbils@amkor.comscrittler@etechsolutions.com)
* @version 1, June 18, 2002
*/
function PadStringToLen(string, char, count)
{
var strLen = len(string);
var padLen = count - strLen;
if (padLen lte 0) {
return string;
}
else {
return RepeatString(char, padLen) & string;
}
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)