padLeft Summary Pads the string with spaces from the left until it reaches the specified width (number of characters). Signatures Click on a signature to select it and view its documentation. public string padLeft(int width) public string padLeft(int minWidth, string fillWith) Usage public string padLeft(int width) public string padLeft(int minWidth, string fillWith) Returns The string prefixed with spaces until it reaches the specified width. The string prefixed with the specified substring until it reaches at least the specified minimum width. Parameters width The width (number of characters) to expand the string to. Parameters minWidth The minimum width (number of characters) to expand the string to. fillWith The string to insert until the specified minimum width is reached. Description Inserts spaces at the beginning of the string until it reaches the specified width (number of characters). If the string already equals or exceeds the specified width (number of characters), nothing will happen. Inserts the specified fillWith string at the beginning of the string until it reaches at least the specified minimum width (number of characters). If the string already equals or exceeds the specified minimum width (number of characters), nothing will happen. If the length of the fillWith string is not a multiple of the specified minimum width, the result may exceed the specified minimum width. Examples Basic Usage 123456import System; string a = "a";Console.log(a.padLeft(4)); // " a"Console.log(a.padLeft(1)); // "a"Console.log(a.padLeft(2)); // " a" Zero Filling from the Left 12345import System; string one = "1";string zeroFilled = one.padLeft(4, "0");Console.log(zeroFilled); // "0001" Share HTML | BBCode | Direct Link