Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 803
LiamGu Avatar asked Aug 25 '09 08:08

LiamGu


1 Answers

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
like image 170
Rob Avatar answered Sep 21 '22 01:09

Rob