tags:

views:

46

answers:

2

I need to get a random character out of a string.

Thanks.

+3  A: 

Get a random number 0 through the length of the string. Ask the string for the nth character.

Some things to try Googling:

  • CharAt
  • Index
  • Rand
  • Random

Of course, add "VB.Net" to your search queries. Use what you know, find what you don't.

Stefan Mai
+1 For a helpful answer. Give a man a program, frustrate him for a day. Teach a man to program, frustrate him for a lifetime...
David Relihan
A: 
Dim str As String = "This is an example String"
Dim rnd As New Random(Date.Now.Millisecond)
Dim index As Int32 = rnd.Next(0, str.Length - 1)
Dim rndChar As Char = str(index)
Tim Schmelter