-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextPadding.fmfn
More file actions
44 lines (38 loc) · 1.12 KB
/
TextPadding.fmfn
File metadata and controls
44 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* @signature: TextPadding ( text ; padChar ; padLength ; alignment )
*
* @source: (original) http://www.briandunning.com/cf/776
*
* @author: Jason Scharf & Fabrice Nordmann
*
* @changelog: v.2, October 2017, Added centering
* @changelog: v.1, Nov 2007 (original by Fabrice Nordmann)
*
* @description: Pads a string on a given length, left or right. Not recursive.
*
* @example: TextPadding ( "James" ; "+-" ; 10 ; "Left" ) --> "James+-+-+"
* @example: TextPadding ( "45.52" ; "." ; 15 ; "Right" ) --> "..........45.52"
**/
Let (
[
~padding = Substitute ( ( 10 ^ padLength ) - 1 ; 9 ; padChar );
~alignment = Case (
alignment = "right" or alignment = "r";
"R";
alignment = "left" or alignment = "l";
"L";
alignment = "center" or alignment = "c";
"C";
/* DEFAULT */
"C"
)
];
Case (
~alignment = "L";
Left ( text & ~padding ; padLength ) ;
~alignment = "R";
Right ( ~padding & text ; padLength );
/* DEFAULT - Center */
Left(Left(~padding; (padLength / 2) - (Length(text)/2)) & text & ~padding; padLength)
)
)