0

I wonder if there are any alternatives to the Python rjust or zfill in DolphinDB.

I want to add zeros(0) on the specified side of a string until it reaches the specified length. How could I do?

Shena
  • 341
  • 1
  • 5

2 Answers2

0

For string

lpad(`Hello, 12, `0);
0000000Hello
rpad(`Hello, 12, `0);
Hello0000000

For decimal

decimalFormat(123,"00000");
00123
Hanwei Tang
  • 413
  • 3
  • 10
0

You can use function lpad and rpad to pad a string with a specific set of characters.

Take lpad for example,

s = "123"
s = lpad(s, 5, "0")

The result is '00123'.

Claire mcc
  • 11
  • 1