There's no need to check whether it converted because it can't possibly not. After executing that code you will have a Char array, no two ways about it. To process each Char in that array, you can use a For Each loop. The things is, you can use a For Each loop on the original String anyway.
Either way, when processing a single Char, the Char structure has several methods that can help you out. Specific to your question, the IsDigit, IsLetter, IsUpper and IsLower methods.
Okay, so I got this now but it doesn't work I don't know why... shows that it is unaccessible due to security after underlying IsLower, IsLower and IsDigit, where have I gone wrong? Thanks!
Dim str As String
Console.WriteLine("Input a character")
str = Console.ReadLine()
Dim OneCharacter As Char() = str
If IsLetter(OneCharacter) Then
If IsLower(OneCharacter) Then
Else : IsDigit(OneCharacter)
Last edited by jmcilhinney; 10-05-2013 at 9:09 AM.
Reason: Added [xcode=vb] for readability
Ah, I got beaten to it again but, the last part of what I was about to post was:-
Finally, The best bit of advice I can give you is to turn Option Strict On. This will help you to identify and correct all Type Conversion errors as you encounter them within your coding. To change this in your current project go to Project->Properties on the IDE's Menu and change the options on the Compile Tab and for all future projects you can do this by going to Tools->Options on the IDE's Menu and changing the VBDefaults.
Well, first of all, how can you assign a String to a Char array variable? Is a String a Char array? In your previous code you were calling ToCharArray so why did you just arbitrarily stop doing that?
I said that you need to use a For Each loop either over that Char array or over the String itself. I don't see any For Each loop.
As I said in my previous post, those methods are members of the Char structure. WriteLine and ReadLine are members of the Console class and look how you're calling them.
The thing is that it is Nested If exercise so I am trying to use nested if, I haven't learned to do For Each loop yet so I am trying to make the code with things I have learned. Not that I am lazy, I just thought there is a way to do it without using For Each loop or any other stuff which I haven't learned yet.
I guess I'll have to learn more about char structure to understand your third point, this is all new to me.
Based on what has already been said then what you need to do is to first of all make sure that only one character has been entered into your console application. If that is True then you can convert that one character of the entered string into a Char value and then do whatever comparisons you need with your If statements. If the string is NOT a Single character then you can display some error message. Here is a quick snippet from your own code:-
If str.Length = 1 Then
Dim oneCharacter As Char = str(0)
'you can now do all your If Statements based on the single character that has been entered
Console.WriteLine("You must only enter one character at a time")