Case-insensitive Sort 1D Array of Strings in LabVIEW

Updated Apr 29, 2024

Reported In

Software

  • LabVIEW

Issue Details

  • I have a 1D array of strings. Is there a way to perform a case-insensitive sort of this array in LabVIEW?
  • The Sort 1D Array function performs a case-sensitive sort of an array of strings. How can I use this function to perform a case-insensitive sort?
image.png
 
 
 

Solution

When using the Sort 1D Array function to sort an array of strings in LabVIEW, each string is compared to each other string one character at a time. The character comparison is based on the ASCII values of the strings, which means that upper-case characters will be sorted before lower-case characters, giving the result shown above.

To sort the strings independently of letter casing, you can utilize Sort 1D Array in the manner shown below. This code sorts an array of clusters of two elements. The first element is a lowercase version of the string, and the second element is the original string.  After the array is sorted, the second element from each cluster is unbundled to generate an array of sorted strings:

image.png

Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.