Hi Readers.
Today I would like to talk about how to split a string on a fixed character (delimiter or separator) via AL.
I recently encountered a small challenge while processing scanned external data. In this case, the QR code contained the Item No., Lot No., and Quantity—all concatenated using a separator, such as a comma, for example, 1896-S,Lot0001,100 or 1908-S,Lot0002,20.
So how can we easily split and extract these values? In Dynamics 365 Business Central: How to split a string into fixed length (Error: The length of the string is xxx, but it must be less than or equal to xxx characters), we briefly discussed how to split a string into fixed length. This time we’ll use a different approach.
The two main points this time:
Text.Split(List of [Text]) Method: Splits a string into a maximum number of substrings based on a collection of separators. For example, in this case, it’s a comma.
List data type: Represents a strongly typed list of ordered objects that can be accessed by index. Contrary to the Array data type, a List is unbounded, such that its dimension does not need to be specified upon declaration.
In other words, the segmented values are stored in a list, allowing us to retrieve each piece of data by its index number
Let’s look at a simple example. First, I added a new test field.
Then split the value of this field.
Done.
It’s very simple. However, it’s important to note that this obviously requires a prerequisite: your data must be quite “clean”. For example, if the master data contains delimiters, it won’t be able to retrieve the correct values.
Great. Give it a try!!!😁
END
Hope this will help.
Thanks for reading.
ZHU
コメント