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.

Usage

public string padLeft(int width)

Returns

The string prefixed with spaces until it reaches the specified width.

Parameters

width

The width (number of characters) to expand the string to.

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.

Examples

Basic Usage
1
2
3
4
5
6
import System;
 
string a = "a";
Console.log(a.padLeft(4)); // "   a"
Console.log(a.padLeft(1)); // "a"
Console.log(a.padLeft(2)); // " a"

Share

HTML | BBCode | Direct Link