VerCompare() [v1.1.36+]

Compares two version strings.

Result := VerCompare(VersionA, VersionB)

매개변수

VersionA

The first version string to be compared.

VersionB

The second version string to be compared, optionally prefixed with one of the following operators: <, <=, >, >= or =.

반환 값

If VersionB begins with an operator symbol, this function returns 1 (true) or 0 (false).

Otherwise, this function returns one of the following to indicate the relationship between VersionA and VersionB:

To check for a specific relationship between the two strings, compare the result to 0. 예를 들어:

a_less_than_b := VerCompare(a, b) < 0
a_greater_than_or_equal_to_b := VerCompare(a, b) >= 0

논평

Version strings are compared according to the same rules as #Requires.

This function should correctly compare Semantic Versioning 2.0.0 version strings, but the parameters are not required to be valid SemVer strings.

This function can be used in a sort callback.

#Requires, Sort

예제

Checks the version of AutoHotkey in use.

if VerCompare(A_AhkVersion, ">=1.1.36.00")
    MsgBox This version has VerCompare built-in.
else
    MsgBox This version < 1.1.36.00.

Demonstrates comparison with pre-release versions.

MsgBox % VerCompare("2.0-a137", "2.0-a136")  ; Returns 1
MsgBox % VerCompare("2.0-a137", "2.0")  ; Returns -1
MsgBox % VerCompare("10.2-beta.3", "10.2.0")  ; Returns -1

Demonstrates a range check.

MsgBox % VerCompare("2.0.1", ">=2.0") && VerCompare("2.0.1", "<2.1")  ; Returns 1