StringTools - Maple Programming Help

StringTools

 pad a string out to a given width on the left
 pad a string on the right to a given width
 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

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{PadLeft}\left("foo",2\right)$
 ${"foo"}$ (1)
 > $\mathrm{PadLeft}\left("foo",3\right)$
 ${"foo"}$ (2)
 > $\mathrm{PadLeft}\left("foo",4\right)$
 ${"foo"}$ (3)
 > $\mathrm{PadLeft}\left("foo",5\right)$
 ${"foo"}$ (4)
 > $\mathrm{PadLeft}\left("foo",6\right)$
 ${"foo"}$ (5)
 > $\mathrm{PadRight}\left("foo",5\right)$
 ${"foo"}$ (6)
 > $\mathrm{PadRight}\left("foo",6\right)$
 ${"foo"}$ (7)
 > $\mathrm{Center}\left("foo",5\right)$
 ${"foo"}$ (8)
 > $\mathrm{Center}\left("foo",6\right)$
 ${"foo"}$ (9)

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

 > $\mathrm{TrimLeft}\left(\mathrm{PadLeft}\left("foo",17\right)\right)$
 ${"foo"}$ (10)
 > $\mathrm{TrimRight}\left(\mathrm{PadRight}\left("foo",17\right)\right)$
 ${"foo"}$ (11)
 > $\mathrm{Trim}\left(\mathrm{Center}\left("foo",17\right)\right)$
 ${"foo"}$ (12)

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

 > $\mathrm{TrimLeft}\left(\mathrm{PadLeft}\left("foo",17\right)\right)$
 ${"foo"}$ (13)

Similar remarks apply to TrimRight and Trim.