Friday, December 2, 2016

Version number strings aren't automatically sorted as versions should be

Let's say you have some strings describing version numbers, like 1.1, 1.2, all the way up to 1.11. If you try to do a newer-version check using only string comparison, it will appear that 1.11 is older than 1.2. Most sorts sort those texts that way because "1" indeed sorts before "2", so it stops checking. (It doesn't think about numeric value at all.)

Instead, you should do some number comparisons. For example, using the SMBIOSBIOSVersion WMI property (a string) will be more difficult than using the SMBIOSMajorVersion and SMBIOSMinorVersion properties, which are integers.

Based on my Super User answer.

No comments:

Post a Comment