
Champion
•
5.5K Messages
•
97.2K Points
Wed, Apr 19, 2017 7:07 AM
Solved
Lightroom SDK: LrStringUtils.compareStrings() doesn't compare strings with digits correctly
LrStringUtils.compareStrings() doesn't compare strings containing digits correctly. For example, it says that "a9b" comes before "a10b":

It appears that compareStrings() is comparing sequences of digits numerically, e.g. as the numbers 9 and 10 in the example above. While that definition can be useful in some cases, such as ordering filenames containing sequence numbers, it is not generally useful for sorting.
The SDK should restore the traditional meaning to compareStrings() and optionally provide a second compare function for the current functionality.
It appears that compareStrings() is comparing sequences of digits numerically, e.g. as the numbers 9 and 10 in the example above. While that definition can be useful in some cases, such as ordering filenames containing sequence numbers, it is not generally useful for sorting.
The SDK should restore the traditional meaning to compareStrings() and optionally provide a second compare function for the current functionality.
Problems
•
Updated
3 years ago
5
5
Helpful Widget
How can we improve?
Tags
No tags available
Responses
Official Solution
melissa_rios
Adobe Administrator
•
109 Messages
•
2.9K Points
3 years ago
This issue should be fixed in today's Lightroom Classic CC 7.2 version. Please update your application and let us know if you still see this issue!
Lightroom Classic CC 7.2 is now available!
Thanks,
Melissa
0
sunil_bhaskaran
Adobe Administrator
•
519 Messages
•
9.8K Points
4 years ago
Let us look into it.
Thanks,
Sunil
0
0
abhishek_kumar_1l77t404li7dx
42 Messages
•
866 Points
4 years ago
E.g.,, image_7 < image_15.
This is because all the filenames or timing data follow this natural order. So, for practical scenarios, this function should suffice. image_7 is supposed to come before image_15 in sorted order.
But, yes the SDK should provide a comparison function similar to C's strcmp().
We'll look into it. And also try to describe the APIs in documentation a bit more.
Thanks for reporting.
Thanks,
Abhishek
1
John_R_Ellis
Champion
•
5.5K Messages
•
97.2K Points
3 years ago
LrStringUtils.compareStrings (string x, string y [, boolean strictAlphanumeric])
Returns true iff the string "x" precedes the string "y" in the user's locale.
If "strictAlphanumeric" is true, the strings are compared using normal alphanumeric comparisons.
If "strictAlphanumeric" is false (the default), sequences of digits within the strings are interpreted as numbers and compared as numbers rather than strings, similar to how Mac Finder and Windows File Explorer sort filenames. For example, "a9x" < "a10x".
More precisely, the strings "x" and "y" are parsed into maximal sequences of non-digits and digits, and the corresponding sequences compared in turn. If corresponding sequences both contain digits only, they are compared as numbers, not strings; otherwise, they are compared as strings.
0
0
sunil_bhaskaran
Adobe Administrator
•
519 Messages
•
9.8K Points
3 years ago
Thanks,
Sunil
0
0