Just pass in a string to the SortString method, and you will get a string in return that is sorted. It won't account for every possiblity, but if you have a string of words that is seperated by spaces, it will work just fine.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show(SortString("This is the new string to sort")) End Sub Private Function SortString(ByVal theString As String) As String Dim arrayOfStrings() As String = theString.Split(" ") Array.Sort(arrayOfStrings) Dim mystrBuilder As System.Text.StringBuilder = New System.Text.StringBuilder() Dim i As Integer For i = 1 To arrayOfStrings.GetUpperBound(0) - 1 mystrBuilder.Append(arrayOfStrings(i) & " ") Next Dim returnString As String = mystrBuilder.ToString() returnString = returnString.Trim() Return returnString End Function




Reply With Quote