[SOLVED] How do I find out if the first character of a string is a number in VB.NET?

Issue

How do I check to see if the first character of a string is a number in VB.NET?

I know that the Java way of doing it is:

char c = string.charAt(0);
isDigit = (c >= '0' && c <= '9');

But I’m unsure as to how to go about it for VB.NET.

Thanks in advance for any help.

Solution

Here’s a scratch program that gives you the answer, essentially the “IsNumeric” function:

Sub Main()
    Dim sValue As String = "1Abc"
    Dim sValueAsArray = sValue.ToCharArray()
    If IsNumeric(sValueAsArray(0)) Then
        Console.WriteLine("First character is numeric")
    Else
        Console.WriteLine("First character is not numeric")
    End If

    Console.ReadLine()
End Sub

Answered By – Rob

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *