Create an array which contains all characters

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
I'm trying to create an array which contains all characters on the keyboard, though I'm saving them as strings. Something is wrong with my declaration of the array, but I don't know what. I'm not finished yet.
VB.NET:
Dim chararray() As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","`","1","2","3","4","5","6","7","8","9","0","~","!","@","#","$","%","^","&","*","(",")","_","+","[","]","\","{","}","|",";","'",":","""}

My error says that vb.net is expecting a bracket or a brace, It's difficult for me to read the small text, and it is underlining the end of my statement.
 
To get the ASCII printable characters range 32-126 you can also loop:
VB.NET:
Dim sb As New System.Text.StringBuilder
For i As Integer = 32 To 126
    sb.Append(Convert.ToChar(i))
Next
Dim chars() As Char = sb.ToString.ToCharArray
 
Thank you, you've both been very helpful. I found out what was wrong with my code, apparently when you are making a string, you cannot contain a quotation within quotations as I did. eg : """
However, I'm probably going to do it Johnh's way. Thanks for showing me the .tochararray function though Neal.
 
If you need to put a quote character in the quoted string you must use two quotes, eg:
VB.NET:
Dim s As String = "Someone said ""hello"" and yawned."
 
Back
Top