4/5

split(): clean up a messy line

Medium

Cut a comma-separated line into pieces, tidy the spacing around each one, and drop anything that is left blank.

" a , , b " becomes {"a", "b"}.

Order matters: a piece that is nothing but spaces only looks blank after it has been trimmed.

Input

  • ri!line — Text

ri! Rule Inputs

ri!lineText
" a , , b "

Example 1 — Spaces and a blank field

Input: ri!line
" a , , b "
Output:
{
  "a",
  "b"
}

Example 2 — Leading, doubled and trailing commas

Input: ri!line
",a,,b,"
Output:
{
  "a",
  "b"
}

Example 3 — Already clean

Input: ri!line
"a,b"
Output:
{
  "a",
  "b"
}

Example 4 — Empty text leaves nothing at all

Input: ri!line
""
Output:
{}

Example 5 — Nothing but separators and spaces

Input: ri!line
" , , "
Output:
{}

Appian Expression Tips

  • • Use ri!variableName for rule inputs
  • • Use a!localVariables(local!x: …, body) for locals
  • • Use a!forEach(items: …, expression: fv!item) to iterate
  • • Use where() / reject(fn!isnull, list) to filter