Home Articles VB.Net Articles Shuffle a string in VB.Net

Shuffle a string in VB.Net

In this tutorial/code example I'm going to show you a method of shuffling a string up. You might use this for something like an anagram game.

    Private ran As New Random
    Private Function randomizeString(ByVal input As String) As String
        Dim rtn As String = ""
        Dim i As Integer

        While input.Length > 0
            i = ran.Next(0, input.Length)
            rtn &= input.Substring(i, 1)
            input = input.Remove(i, 1)
        End While

        Return rtn
    End Function

Last Updated (Saturday, 23 October 2010 23:03)