In this video, I show how Text.Split and the List data type makes a great pair for text parsing. The method can avoid lots of copystr-strpos gymnastics.

In this video, Erik demonstrates how to use the Text.Split function in AL to parse strings in Business Central. Specifically, he revisits a function from a previous video on app security, where he extracts information from the call stack — all without using traditional string manipulation functions like CopyStr, StrPos, or Substring.
The Problem: Parsing the Call Stack
In Erik’s security app demo, there’s a function called GetLastErrorCallStack that returns a long text string representing the call stack. This string contains multiple lines of information separated by backslash characters (\). Each line contains details about the object, method, app name, and publisher — all packed into a single string that needs to be parsed.
A typical call stack string looks something like this:
"BCThreadProtection Codeunit.FakeError - SomeAppName by Default publisher\AnotherObject.Method - AnotherApp by AnotherPublisher\"
The key observations about this format are:
- Multiple lines are separated by a backslash (
\) - Within each line, the object/method and the app/publisher info are separated by
-(space-dash-space) - The app name and publisher are separated by
by(space-by-space)
Using Text.Split to Break It Down
Step 1: Split the Call Stack into Individual Lines
The first step is to take the entire call stack string and split it into individual lines using the backslash as a delimiter. The Split function returns a List of [Text], which is one of the newer data types in AL:
stack := stackTxt.Split('\');
After this call, stack is a List of [Text] where each element represents one line from the call stack. Note that if the string ends with a backslash, you’ll get an empty entry at the end of the list — something to be aware of when processing the results.
Step 2: Get the Specific Line of Interest
In this demo, the security app knows that the interesting entry is the eighth item on the stack (because the error-collecting mechanism adds seven steps to the call stack). So we retrieve that specific line:
stack.Get(8)
This returns a single text string representing one line from the call stack.
Step 3: Chain Splits to Extract the App Name
Here’s where it gets really elegant. Erik chains multiple Split and Get calls together in a single line to extract exactly the information he needs:
// To get the app name:
appName := stack.Get(8).Split(' - ').Get(2).Split(' by ').Get(1);
// To get the publisher:
publisher := stack.Get(8).Split(' - ').Get(2).Split(' by ').Get(2);
Let’s break down what’s happening in that one-liner for the app name:
stack.Get(8)— Gets the eighth line from the call stack list (a text value).Split(' - ')— Splits that line by" - ", separating the object/method from the app/publisher info.Get(2)— Gets the second part (the app name and publisher).Split(' by ')— Splits that part by" by ", separating the app name from the publisher.Get(1)— Gets the first part, which is the app name
For the publisher, the only difference is the final step uses .Get(2) instead of .Get(1) to retrieve the publisher name rather than the app name.
A Word of Caution
Erik openly acknowledges that this approach has limitations. If the app name or publisher name happens to contain the string " by " or " - ", the parsing would break. For a prototype or controlled environment this is perfectly fine, but a production-ready implementation would need additional validation — such as checking the number of elements returned by each split to ensure the data structure matches expectations.
The Project Setup
For reference, here’s the app.json for the demo project:
{
"id": "c3f36c7a-dd95-47bf-83f0-cbaedad6dce5",
"name": "SplitTextInLines",
"publisher": "Default publisher",
"version": "1.0.0.0",
"platform": "1.0.0.0",
"application": "21.0.0.0",
"idRanges": [
{
"from": 50400,
"to": 50449
}
],
"runtime": "10.0",
"features": [
"NoImplicitWith"
]
}
Summary
The Text.Split function in AL is a powerful tool for string parsing. By chaining Split and Get calls, you can extract specific pieces of information from structured strings in a single, readable line of code — all without resorting to CopyStr, StrPos, StrLen, or Substring. If your string has a “splittable nature” with consistent delimiters, Text.Split can dramatically simplify your parsing logic and make your code much more concise and maintainable.