2016-09-29 4 views

Antwort

2
Option Explicit 

Function sortingHat(str As String, _ 
        Optional delim As String = ",") 
    Dim a As Long, b As Long, arr As Variant, tmp As Variant 

    'split the string into an array 
    arr = Split(str, delim) 

    'sort the array 
    For a = LBound(arr) To UBound(arr) - 1 
     For b = a + 1 To UBound(arr) 
      If arr(b) < arr(a) Then 
       tmp = arr(a) 
       arr(a) = arr(b) 
       arr(b) = tmp 
      End If 
     Next b 
    Next a 

    'join the array into a string 
    sortingHat = Join(arr, delim) 
End Function 

sortingHat

+0

LOL - der Funktionsname allein ist eine Up-Vote wert. – Comintern

0

Bedenken Sie:

Function MySort(txt As String, Sep As String) As String 

    Dim a 

    With CreateObject("System.Collections.ArrayList") 
     For Each a In Split(txt, Sep) 
      .Add Trim$(CStr(a)) 
     Next 
     .Sort 
     MySort = Join(.ToArray, Sep) 
    End With 
End Function 

enter image description here

HINWEIS:

Wie im Titel angefordert, führt die Funktion eine alphabetisch eher sortieren als numerisch sortieren.

Verwandte Themen