Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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()

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...