Lia*_*mGu 5 vb.net asp.net string
如何检查字符串的第一个字符是否是VB.NET中的数字?
我知道Java的做法是:
char c = string.charAt(0);
isDigit = (c >= '0' && c <= '9');
Run Code Online (Sandbox Code Playgroud)
但我不确定如何为VB.NET做到这一点.
在此先感谢您的帮助.
这是一个临时程序,为您提供答案,主要是"IsNumeric"函数:
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
Run Code Online (Sandbox Code Playgroud)
Public Function StartsWithDigit(ByVal s As String) As Boolean
Return (Not String.IsNullOrEmpty(s)) AndAlso Char.IsDigit(s(0))
End Function
Run Code Online (Sandbox Code Playgroud)