Consider that you have a list of Strings like “File 1, File 2, File 3,… File 10, File 11… File 20”.
When you do default LabVIEW sorting of above string array, the string “File 10” would occur after “File 1” and before “File 2”. But what we ideally want is, the sorted elements to be in the order “File 1, File 2,… File 10, File 11,…, File 20”.
This can be done using the open source reusable “Alpha Numeric Sort 1D Array”, which is part of “SLL Toolkit”, an open source LabVIEW toolkit.
How does this work?
The tool splits each string into an array of sortable clusters containing the numeric and string parts - which then gets sorted in the order that we want. We take the string and get 1st numeric component (if not present, it will be taken as 0), then we take the next string component. This process gets repeated till the entire string is exhausted. This array of clusters is then sorted, which gives our required sorted output.
LabVIEW block diagram of the logic is available below.
For example, if the string is “File 1 Item 21.txt”, the sortable cluster is:
The reason why it maintains a numeric array instead just numeric is, there are multiple scenarios where the string would contain a non-standard number like date, time stamp and IP address. To handle those cases in a generic manner, a numeric array is used.
For example, if the string is “File 14.01.2022 Item 21.txt”, the sortable cluster element is:
Installing SLL Toolkit
SLL Toolkit is an open source LabVIEW toolkit (MIT License) with a collection of useful general purpose LabVIEW reusables like the Alpha Numeric String Sorting.
You can install SLL Toolkit using VI Package Manager:
Source code for SLL Toolkit is available in GitHub:
https://github.com/solitontech/SLL-Toolkit
No comments:
Feel free to leave a piece of your mind.