16,550
社区成员
发帖
与我相关
我的任务
分享
Dim i As Int32
If (Int32.TryParse(textBox1.Text, i)) Then
MsgBox("是整数")
End If
Public Function IsInteger(ByVal Value As String) As Boolean
If Value Is Nothing OrElse _
Value.Length < 1 OrElse _
Value.Length > 11 OrElse _
Value.IndexOf("-") > 0 _
Then Return False
Dim iASC As Integer
For Each c As Char In Value
iASC = Asc(c)
If (iASC < 48 OrElse iASC > 57) AndAlso iASC <> 45 Then Return False
Next
Return True
End Function
'调用示范:
IsInteger("01234") '返回True
IsInteger("-1234") '返回True
IsInteger("3.14") '返回False
IsInteger("12-4") '返回False
IsInteger(Nothing) '返回False
IsInteger(String.Empty)'返回False
IsInteger("") '返回False