DonnaF Posted June 23, 2003 Posted June 23, 2003 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 Quote
*Experts* mutant Posted June 23, 2003 *Experts* Posted June 23, 2003 I dont see you actually assigning the line to any variable, you just read without doing anything to it. Console.ReadLine().ToCharArray() Assign some variable to it: yourarray = Console.ReadLine().ToCharArray() Quote
DonnaF Posted June 24, 2003 Author Posted June 24, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.