Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version next

...

Column reference example:

PAD
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextset col: Whse_Nbr value:
pad(Whse_Nbr, 6, '0', left)

...

pad(Whse_Nbr

...

, 6, '0', left)

Output: Returns a value of a minimum of six characters in length. For

...

input values that are shorter, the character 0 is added to the left side of the string.

String literal example:

PAD
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
pad('My Name', 10, '!', right)

...

pad('My Name', 10, '!', right)

Output: Returns the string: My Name!!!! is written to the new column.

D s
snippetSyntax

PAD
d-codelang-syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value:
pad(string_val,string_length,pad_string,pad_side)

pad(string_val,string_length,pad_string,pad_side)


ArgumentRequired?Data TypeDescription
string_valYstringName of the column, function returning string values, or string literal to be applied to the function
string_lengthYinteger (positive)Minimum number of characters in the output string.
pad_stringNstringString, column reference, or function returning a string to apply to strings that are less than the minimum length. Default is whitespace.
pad_sideNenum
  • left - any padding is applied to the left side of the string (default)
  • right - any padding is applied to the right side of the string

...

When the pad string contains multiple characters, the behaviors are different depending on the side on which the string is padded:

FunctionOutput Value
PAD
Code Block
D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextpad('12',
4,
'abc'
left)

pad('12', 4, 'abc' left)

Code Block
bc12
PAD
Code Block
D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextpad('12',
4,
'abc'
right)

pad('12', 4, 'abc' right)

Code Block
12ab
PAD
Code Block
D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextpad('12',
6,
'abc'
left)

pad('12', 6, 'abc' left)

Code Block
cabc12
PAD
Code Block
D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextpad('12',
6,
'abc'
right)

pad('12', 6, 'abc' right)

Code Block
12abca


D s
snippetusage

...

prodIdprodName
1Our First Product
2Our Second Product
3Our First Product v2
1001

A New Product Line

1002A New Product Line v2

TransformTransformation:

The first step is to convert the product identifiers to string values:

d-

...

trans
RawWrangletrue
Typestep
WrangleTextsettype col: prodId type: 'String'
p01NameColumns
p01ValueprodId
p02NameNew type
p02Value'String'
SearchTermChange column data type

Then, you can apply the character 0 as padding to the left of these strings, so that all values are four characters in length at a minimum:

d-

...

trans
RawWrangletrue
Typestep
WrangleTextset col:prodId value:

...

pad(prodId,4,'0',left)
p01NameColumns
p01ValueProdId
p02NameFormula
p02Valuepad(prodId,4,'0',left)
SearchTermEdit column with formula

Results:

prodIdprodName
0001Our First Product
0002Our Second Product
0003Our First Product v2
1001

A New Product Line

1002A New Product Line v2

...