Shuffle a string in VB.Net

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

2 thoughts on “Shuffle a string in VB.Net”

  1. Pingback: Shuffle a string in C# | Sam Jenkins' Blog

Leave a Comment

Your email address will not be published. Required fields are marked *

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