Center - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


StringTools

  

PadLeft

  

pad a string out to a given width on the left

  

PadRight

  

pad a string on the right to a given width

  

Center

  

centre a string in a given width

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

PadLeft( s, width, padchar )

PadRight( s, width, padchar )

Center( s, width, padchar )

Parameters

s

-

Maple string; string to be padded

width

-

non-negative integer; width of the resulting string

padchar

-

(optional) pad character to use

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 optional padchar argument can be used to specify that a character other than the space be used to pad the string.

• 

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.

• 

All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

> 

with⁡StringTools:

> 

PadLeft⁡foo,2

foo

(1)
> 

PadLeft⁡foo,3

foo

(2)
> 

PadLeft⁡foo,4

foo

(3)
> 

PadLeft⁡foo,5

foo

(4)
> 

PadLeft⁡foo,6

foo

(5)
> 

PadRight⁡foo,5

foo

(6)
> 

PadRight⁡foo,6

foo

(7)
> 

Center⁡foo,5

foo

(8)
> 

Center⁡foo,6

foo

(9)
> 

PadLeft⁡foo,8,x

xxxxxfoo

(10)
> 

PadRight⁡foo,8,x

fooxxxxx

(11)
> 

Center⁡foo,8,x

xxxfooxx

(12)

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

> 

TrimLeft⁡PadLeft⁡foo,17

foo

(13)
> 

TrimRight⁡PadRight⁡foo,17

foo

(14)
> 

Trim⁡Center⁡foo,17

foo

(15)

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

> 

TrimLeft⁡PadLeft⁡ foo,17

foo

(16)

Similar remarks apply to TrimRight and Trim.

See Also

string

StringTools

StringTools[IsSpace]

StringTools[Trim]