In this tutorial/code example I’m going to show you a method to shuffle the contents of a string. 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
Shuffle a string in VB.Net
Tagged on:     

2 thoughts on “Shuffle a string in VB.Net

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.