pad a string out to a given width on the left - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : StringTools Package : WhiteSpace Utilities : StringTools/Pad

StringTools[PadLeft] - pad a string out to a given width on the left

StringTools[PadRight] - pad a string on the right to a given width

StringTools[Center] - centre a string in a given width

Calling Sequence

PadLeft( s, width )

PadRight( s, width )

Center( s, width )

Parameters

s

-

Maple string; string to be padded

width

-

non-negative integer; width of the resulting string

Description

• 

The PadLeft(s, width) command adds spaces to the left of the string s to produce a string of length equal to width. If width is less than or equal to the length of s, then s is returned unchanged.

• 

The PadRight(s, width) command adds spaces to the right of the string s to produce a string of length width. If width is less than or equal to the length of s, then s is returned unchanged.

• 

The Center(s, width) command adds spaces to both ends of the string s to produce a string of length width. If width - length(s) is even, then an equal number of spaces are added to the left and right ends of s. If width - length(s) is odd, then the extra space is added to the left of s.

• 

The StringTools[TrimLeft], StringTools[TrimRight] and StringTools[Trim] commands are approximate inverses of PadLeft, PadRight and Center, respectively.

Examples

withStringTools:

PadLeftfoo,2

foo

(1)

PadLeftfoo,3

foo

(2)

PadLeftfoo,4

foo

(3)

PadLeftfoo,5

foo

(4)

PadLeftfoo,6

foo

(5)

PadRightfoo,5

foo

(6)

PadRightfoo,6

foo

(7)

Centerfoo,5

foo

(8)

Centerfoo,6

foo

(9)

The Trim* procedures are approximate inverses to the Pad* and Center procedures.

TrimLeftPadLeftfoo,17

foo

(10)

TrimRightPadRightfoo,17

foo

(11)

TrimCenterfoo,17

foo

(12)

The TrimLeft procedure is not quite an inverse of PadLeft, however.

TrimLeftPadLeft foo,17

foo

(13)

Similar remarks apply to TrimRight and Trim.

See Also

string, StringTools, StringTools[IsSpace], StringTools[Trim]


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam