- Home
·
- String Manipulation
·
- This code will alphabetize any string inserted. For best results, remove any spaces. This code assu
This code will alphabetize any string inserted. For best results, remove any spaces. This code assu
This code will alphabetize any string inserted. For best results, remove any spaces. This code assumes that the string is in one case;
Rate This code will alphabetize any string inserted. For best results, remove any spaces. This code assu
(1(1 Vote))
Private Function Alphabetize(ByVal originalString As String) As String
Dim alphabetizedString As String = ""
Dim tempString As String
Dim Iterator As Integer
Dim closestToA As Char
Dim positionToRemove As Integer
Dim charsToRemove As Integer
Dim tempIterator As Integer
tempString = originalString
charsToRemove = tempString.Length
' Two For loops to work through the string; first one is to ensure
' removal of one character each pass; second one loops through
' all characters in the current temporary string
For Iterator = 0 To charsToRemove - 1
' Set the character closest to a as equal to the first character
' of the temporary string
closestToA = tempString.Chars(0)
positionToRemove = 0
For tempIterator = 1 To tempString.Length - 1
If tempString.Chars(tempIterator) < closestToA Then
closestToA = tempString.Chars(tempIterator)
positionToRemove = tempIterator
End If
Next tempIterator
' Remove selected character from tempstring and append it to alphabetizedString
tempString = tempString.Remove(positionToRemove, 1)
alphabetizedString &= closestToA.ToString
Next Iterator
Return alphabetizedString
End Function ' Alphabetize
This code will alphabetize any string inserted. For best results, remove any spaces. This code assu Comments
No comments yet — be the first to post one!
Post a Comment