All functions

Appian split()

Cut text into a list on a separator. Simple until the data has a trailing comma, and then the blank pieces it leaves behind are the whole story.

Official Appian documentation

The shape

split() cuts a piece of text wherever a separator appears and hands back the pieces as a list.

split("a,b,c", ",")   →   {"a", "b", "c"}

The separator is text, not a single character, so split(line, ", ") cuts on a comma followed by a space and the pieces come back already tidy.

You always get a list back

Even when the separator never appears. split("abc", ",") gives {"abc"} — a list of one, not the plain text you started with. Anything reading the result has to expect a list.

The blanks are the whole difficulty

A separator with nothing between it and the next one produces an empty piece, and so does one at either end:

split("a,,b", ",")   →   {"a", "", "b"}
split(",a,", ",")    →   {"", "a", ""}

Real data is full of these — a trailing comma, a double comma where a value was missing. They are not errors and nothing warns you; they are simply blank items sitting in your list, and they will show up wherever you render it.

The standard cleanup is to reject them:

reject(fn!isnullorempty, split(line, ","))

Empty text is the trap that bites hardest

split("", ",") gives {""}. That is a list holding one empty piece, not an empty list, so counting it gives 1 and not 0.

Anything that counts fields on possibly-empty input is wrong by one until this is handled. Rejecting the blanks first fixes it, because then there is genuinely nothing left.

Tidying every piece at once

trim() applies itself to a whole list, so you do not need a loop to clean up spacing:

trim(split(" a , b ", ","))   →   {"a", "b"}

Trim first, then reject: a piece that is nothing but spaces only looks empty once it has been trimmed.

Going back the other way

joinarray(list, separator) is the inverse, which makes swapping one separator for another a single round trip:

joinarray(split("a,b,c", ","), " | ")   →   "a | b | c"

Try it

Run each one and read what comes back before moving on.

1Cut a comma-separated line into its pieces.

split("a,b,c", ",")

2Now split on a separator that is not in the text at all.

split("abc", ",")

Put two separators next to each other.

split("a,,b", ",")

Split empty text and count what comes back.

count(split("", ","))

1Clean up the spacing around every piece, without a loop.

trim(split(" a , b ", ","))

2Now deal with a genuinely messy line: leading, doubled and trailing separators.

reject(fn!isnullorempty, split(",a,,b,", ","))

Independent evaluator — approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

Exercises

0 of 5 cleared
  1. 1split(): cut a line into fields
  2. 2split(): count the fields on a line
  3. 3split(): pull the email out of a CSV line
  4. 4split(): clean up a messy line
  5. 5split(): turn a CSV header and row into a record
Start the first exercise