Automatic update: how to disable automatic update in Windows 7
Comparison of version numbers
When automatic updates are implemented, the version number must be compared.
For example, compare the sizes of 1.0.6 and 1.0.7.
Solution:
Convert the string of the version number to an integer for comparison.
Steps:
1. Remove the decimal point in the string. (Use regular expressions)
2. Compare the length of two strings, and add 0 after the shorter end until the two strings have the same length. (To compare 1.0.5.1 and 1.0.6 ).
3. convert two strings to integer comparison.
The Code is as follows:
// Regular expression removes decimal point
// String str1 = "1.0.6" .replaceAll ("[.]", "");
// String str2 = "1.0.7" .replaceAll ("[.]", "");
String str1 = "1.0.5.1" .replaceAll ("[.]", "");
String str2 = "1.0.6" .replaceAll ("[.]", "");
The
// Add 0 padding for tails with different lengths
if (str1.length () <str2.length ()) {
for (int i = 0; i <str2.length ()-str1.length (); i ++) {
str1 + = "0";
}
} else {
for (int i = 0; i <str1.length ()-str2.length (); i ++) {
str2 + = "0";
}
}
The
int i1 = Integer.valueOf (str1);
int i2 = Integer.valueOf (str2);
The
System.out.println ("str1 => i1 =" + i1);
System.out.println ("str2 => i2 =" + i2);