FCF 2.0 development in progress...
> > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

fcf.pad() function

string fcf.pad(string a_str, number a_len, string a_fill = " ", "l"|"left"|"r"|"right"|"c"|"center" a_align = "left")

Package: fcf-framework-core

File: fcf-framework-core:fcf.js

Available from version: 2.0.2

Pads a string to a given length

Arguments

string a_str
- Source string

integer a_len
- The length to which to pad the source string. If the original string is greater than or equal to the specified length, the original string is returned unchanged.

string a_fill = " "
- The string whose characters will be filled in the source string

"l"|"left"|"r"|"right"|"c"|"center" a_align = "left"
- Line alignment when filling. The parameter can take one of the following values:

"l"|"left" - Alignment is performed on the left edge, padding with additional characters occurs from the right edge

"r"|"right" - Alignment is performed on the right edge, padding with additional characters occurs from the left edge

"c"|"center" - Alignment is performed on the center, filling with additional characters occurs from the left and right edges

Result
string
- Result string

Example: Default mode

let newString = fcf.pad(`text`, 7); console.log(`"${newString}"`);

Output:

"text "

Example: Right align

let newString = fcf.pad(`98`, 7, "0", "r"); console.log(`"${newString}"`);

Output:

"0000098"

Example: Center align

let newString = fcf.pad(`text`, 10, " ", "center"); console.log(`"${newString}"`);

Output:

" text "