Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Pad Number / Text Left
Prepend repeating pad characters until text reaches desired target length.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Text & Strings). Copy the parameterized template or run the self-contained example.
- 1Category: Text & Strings
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
to padLeft text targetLen padChar
curLen is length of text
if curLen is at least targetLen
return text
.
needed is targetLen minus curLen
padding is ""
count from 1 to needed as idx
padding is padding plus padChar
.
return padding plus text
.
to padLeft text targetLen padChar
curLen is length of text
if curLen is at least targetLen
return text
.
needed is targetLen minus curLen
padding is ""
count from 1 to needed as idx
padding is padding plus padChar
.
return padding plus text
.
res is padLeft "item" 7 "x"
say "Padded:" res
if res is not "xxxitem"
fail with "padLeft mismatch: expected xxxitem"
.
if length of res is not 7
fail with "padLeft length mismatch: expected 7"
.
Installation & Usage
otter snippet inspect text-pad-left
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.