Console.Readline.ToCharArray

DonnaF

Freshman
Joined
Mar 20, 2003
Messages
30
I've having trouble with the code below. A user will enter a line of text, and the text will then be saved in an array. The first character of the text is saved, and then used in a For Each loop to determine how many times that character appears in the text. When I execute this code, I get blanks in the array instead of the text. Does anyone see anything wrong with my code?

Thanks, Donna


Sub Main()
Dim textArray As Char() = New Char(79) {}
Dim savechar As Char
Dim intCount As Integer

Console.WriteLine("Enter a Line of Text")
Console.ReadLine().ToCharArray()
savechar = textArray(0)
Console.WriteLine(textArray)

For Each savechar In textArray
intCount += 1
Next

Console.WriteLine(savechar & " occurs " & intCount & " times.")

End Sub
 
I dont see you actually assigning the line to any variable, you just read without doing anything to it.
Visual Basic:
Console.ReadLine().ToCharArray()
Assign some variable to it:
Visual Basic:
yourarray = Console.ReadLine().ToCharArray()
 
Mutant, thank you for noticing I didn't assign the value to a variable. I stared at it too long, and didn't see it. Also, I'm new in working with VB.Net.

It works fine now. Thanks again for your help, Donna
 
Back
Top