Sorting letters within a string alphabetically
Hey everybody,
I hope that someone can help me with my problem:
I'm trying to built a function that can sort the letters within a string alphabetically.
I figured out how to do it in Excel, but I don't know how to get it done in IDEA Basic.
Option Explicit
Public Function sortieren(zelle) As String
Dim objAL As Object
Dim I As Integer
Set objAL = CreateObject("System.Collections.Arraylist")
With objAL
For I = 1 To Len(zelle.Text)
.Add (Mid(zelle.Text, I, 1))
Next
.Sort
sortieren = Join(.toArray, "")
End With
Set objAL = Nothing
End Function
Thanks a lot
Hi Brian,
Hi Brian,
thanks for your message :-)
I played around with your script for a while but I don't seem to be able to get what I want.
Is there a way to build a user defined function which I can use in an added field of my table to get the following result: "Stephan" --> "aehnpSt"
This would be exactly the same what I managed to do in Excel.
Maybe you can help me out again
Thanks Stephan, I understand
Thanks Stephan, I understand now. Is this part of a script as you can do this with a Custom Function as part of the equation editor so you don't actually need a script. The only problem with doing sorting is an A is not the same as an a, so your first item would probably be AGHSaccehhmnnoortu as capitals are sorted as lower than lower case (I think).
Brian
Hi Stephan,
Hi Stephan,
Here is an example using the internal IDEAScripting array and then sorting it. This array is for integers but it can be easily changed for strings. I have used the collections in the past but usually I stick with the internal array structure if I can.
Here is an example of a list of random number before being sorted:
and after:
Here is the code to generate the array and do the sort: