How to sort array of version number strings in VBScript?

后端 未结 1 1717
情话喂你
情话喂你 2020-12-22 10:50

I am using SVN and tags to label releases, with each tag directory named with the version number. This is all fine, but now I am in the process of automating this build proc

相关标签:
1条回答
  • 2020-12-22 11:11

    As VBScript has no native sort, you'll have to use other techniques: Javascript/JScript with a suitable sort function, a disconnected ADO recordset, or a .NET ArrayList with a bit of creative formatting. To demonstrate the last option:

      Dim aTests : aTests = Array( _
          "1.0.1"  _
        , "1.0.10" _
        , "1.0.2"  _
      )
      WScript.Echo Join(aTests, vbCrLf)
      Dim oFmt   : Set oFmt   = New cFormat
      Dim alVers : Set alVers = CreateObject("System.Collections.ArrayList")
      Dim sVers
      For Each sVers In aTests
          Dim aParts : aParts = Split(sVers, ".")
          alVers.Add oFmt.formatArray("{0,4}.{1,4}.{2,4}", aParts)
      Next
      alVers.Sort
      WScript.Echo "---------------"
      WScript.Echo Join(alVers.ToArray(), vbCrLf)
      WScript.Echo "---------------"
      For Each sVers In alVers
          WScript.Echo Replace(sVers, " ", "")
      Next
    

    output:

    1.0.1
    1.0.10
    1.0.2
    ---------------
       1.   0.   1
       1.   0.   2
       1.   0.  10
    ---------------
    1.0.1
    1.0.2
    1.0.10
    

    Get the cFormat Class from here

    0 讨论(0)
提交回复
热议问题