VB.net, 2.10 is smaller than 2.2

Alexander Stolte

Expert
Licensed User
Longtime User
On the Filesystem i have the following folders:
upload_2019-12-12_16-11-54.png

B4X:
[ATTACH=full]86277[/ATTACH]
Sorted by name.
If i want to get all these folder with:
B4X:
Dim tmp_unsortet() As String = System.IO.Directory.GetDirectories(path)

then the ordner is:
B4X:
2.10
2.1
2.2
2.3
.
.
.
.

someone has a trick?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use B4J:

B4X:
'make sure not to add whitespace to the string.
Dim s As String = $"2.10
2.1
2.2
2.3"$
Dim sorted As B4XOrderedMap = B4XCollections.CreateOrderedMap
For Each line As String In Regex.Split("[\r\n+]", s)
   Dim m As Matcher = Regex.Matcher("(\d+)\.(\d+)", line)
   If m.Find Then
       sorted.Put(m.Group(1) + m.Group(2) / 1000, line)
   End If
Next
sorted.Keys.Sort(True)
For Each key As Object In sorted.Keys
   Log(sorted.Get(key))
Next

You should of course use the values from File.ListFiles instead of s.
 
Top